473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ASPNET 2.0 Page_Load question

Hi,

In my ASPNet 2.0 C# web application Form1.aspx, there are 1 TextBox control
txtBox1, 1 Button control Btn1, and 1 GridView control GV1.
I found whenever I click the Button control Btn1, then the Page_Load event
will be called first.
This also applys to the situation when I check a CheckBox in the GV1.
I am wondering why in the aspx web form, whenever we click any controls,
they all call the Page_Load event?
Thanks for help.
Jason
Sep 21 '07 #1
5 1470
The page load will allways fire before any of the the events caused by
button pushes etc. It is a programatic requirement to be able to do things
at this time before other events load.

"Jason Huang" <Ja************@hotmail.comwrote in message
news:ut**************@TK2MSFTNGP06.phx.gbl...
Hi,

In my ASPNet 2.0 C# web application Form1.aspx, there are 1 TextBox
control txtBox1, 1 Button control Btn1, and 1 GridView control GV1.
I found whenever I click the Button control Btn1, then the Page_Load event
will be called first.
This also applys to the situation when I check a CheckBox in the GV1.
I am wondering why in the aspx web form, whenever we click any controls,
they all call the Page_Load event?
Thanks for help.
Jason

Sep 21 '07 #2
Hi, Jason.

re:
!I found whenever I click the Button control Btn1, then the Page_Load event will be called first.

That's because you're POSTing the page when you click the button.

Please review the ASP.NET Page Lifecycle ...

http://msdn2.microsoft.com/en-us/lib...72(VS.80).aspx

re:
!I am wondering why in the aspx web form, whenever we click any controls, they all call the Page_Load event?

Do you have autopostback set to "true" ?

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Jason Huang" <Ja************@hotmail.comwrote in message news:ut**************@TK2MSFTNGP06.phx.gbl...
Hi,

In my ASPNet 2.0 C# web application Form1.aspx, there are 1 TextBox control txtBox1, 1 Button control Btn1, and 1
GridView control GV1.
I found whenever I click the Button control Btn1, then the Page_Load event will be called first.
This also applys to the situation when I check a CheckBox in the GV1.
I am wondering why in the aspx web form, whenever we click any controls, they all call the Page_Load event?
Thanks for help.
Jason

Sep 21 '07 #3
The default behavior of a button control is to generate a postback. Other
controls can be set to generate a postback with their events (such as
TextChanged for textbox). A postback is nothing more than a form posting to
itself.

Page_Load always runs when a page is loaded, whether it is a postback or
not. Then, for any other events such as a button click, their event handler
code is run.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Jason Huang" wrote:
Hi,

In my ASPNet 2.0 C# web application Form1.aspx, there are 1 TextBox control
txtBox1, 1 Button control Btn1, and 1 GridView control GV1.
I found whenever I click the Button control Btn1, then the Page_Load event
will be called first.
This also applys to the situation when I check a CheckBox in the GV1.
I am wondering why in the aspx web form, whenever we click any controls,
they all call the Page_Load event?
Thanks for help.
Jason
Sep 21 '07 #4
"Jason Huang" <Ja************@hotmail.comwrote in message
news:ut**************@TK2MSFTNGP06.phx.gbl...
I found whenever I click the Button control Btn1, then the Page_Load event
will be called first.
In addition to the other responses, you can use the IsPostBack property of
the Page object to determine whether your code within the Page_xxx events
runs or not...

if (!IsPostBack)
{
// run when the page first loads
}
else
{
// run when the page posts back to itself
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 21 '07 #5

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ue**************@TK2MSFTNGP03.phx.gbl...
"Jason Huang" <Ja************@hotmail.comwrote in message
news:ut**************@TK2MSFTNGP06.phx.gbl...
>I found whenever I click the Button control Btn1, then the Page_Load
event will be called first.

In addition to the other responses, you can use the IsPostBack property of
the Page object to determine whether your code within the Page_xxx events
runs or not...

if (!IsPostBack)
{
// run when the page first loads
}
else
{
// run when the page posts back to itself
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Once more you have taught me something Mark. I just encountered this as
well and had to devise code to make things work as I wanted. I had a page
that could be invoked from another page and pass nothing, or from a url
click that involved passing four variables. This drove me crazy until I
figured out that the page load occurred first. Having IsPostBack would have
solved my problem in a hardened manner, rather than the kluge I put
together. Thanks.

Shelly
Sep 23 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim H | last post by:
I coded my first asp form and attempted to display a text message from a component. The static text "Our component says:" shows on the aspx page, but the text line from the component does not show....
3
by: dryer | last post by:
I have a web app that runs fine on my local machine (W2K pro), but when ran on Windows 2003 server there is a glitch. I have a function that writes an XML doc to a directory, but I can't figure...
0
by: Miller Lee | last post by:
Hello, In my project, something really trouble me. Let me describe it with an example. I build a project called WaitMe, in this project, I build two page,...
2
by: PinoyDotnet | last post by:
I am just starting 2.0, so I have this In ASPNET 1.X there is a method called InitializeComponent() which clearly wires in the Page_Load method to the Load event, like this: private void...
5
by: Thiago Campos Pereira | last post by:
I need a support of the staff of the Microsoft. Since the beginning of the year I am working in the CFLCL (Company of the sector of energy with more than 15000 employees). I am trying to...
6
by: Dariusz Tomon | last post by:
Hi How can I get url of page so taht I can pass it to string varaible. I have got several urls in my IIS under one folder. I want to have one default.aspx where code under it recognize which...
7
by: Kenny M. | last post by:
Hi I want to write de content of a variable from my asp net code into the Title Bar of the Browser each time I need to switch between those world (HTML-ASPNET) I suffer cause I don’t have...
5
by: Harlan Messinger | last post by:
I installed the Northwind database in my SQL Server developer version, added to the server logins, and in OSQL ran use Northwind GO grant all to GO These executed without error. But my...
16
by: Mich | last post by:
Hi, i'm building an web application for anonymous users. They can take a look in the website, nothing more. In order to perform other actions, the anonymous user must be logged. So i create an...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.