Solved

What exactly happens when a Page_Load event is triggered in ASP.NET ?

Posted on 2002-05-17
8
261 Views
Last Modified: 2012-06-27
In ASP.NET you code for the Page_Load sub insite a <SCRIPT> block whose "runat" property is set to 'server'.

This means that the <SCRIPT> block will be processed at the server end. But the Page_Load event is fired when the ASP.NET page loads into the browser, so that would be a  <<< client-side event >>, if I've understood that correctly.

So if I have for eg. a label control on my page to which I set some value in the Page_Load sub, then who exactly is setting the value of the label control ? The client or the server.

If it is the server then my query is, does the client notify the server in some way when the Page_Load event has occurred at the client end and consequently, the server during the page loading process itself, sets the value of the label.

On the otherhand, if it were the client that sets the value of label control during page load, how is that possible ? Coz once the page is sent to the clien by the server, that's the end of story. Meaning one full cycle of client-server interaction is over and the server will won't do anything until the next request is initiated from the cleint end or the browser.

So what exactly is the mechanism at work ?

The confusion in my mind is more with respect the text I have bracketed in angle brackets above. So who exactly does the job of setting the value of the label control and how ?
0
Comment
Question by:x666xchange
  • 6
  • 2
8 Comments
 
LVL 23

Expert Comment

by:naveenkohli
ID: 7016830
The processing occurs on server side. Its the .Net framework on server side that is setting the values of the controls.
For example
<asp:Label id="myLabel" Runat=server Text="Foo"></asp:Label>

When server side processes the page, it creates an instance of asp:Label class object. All the controls have some common properties like ID, Text etc. It assigns the values to these properties that you specified in the tag itself. After all the properties have been set, the framework calls Render method on each control. In response to each render call, the controls emit the corresponding HTML tag. For example, incase of Label control, it will emit <span> tag. And on post backs, the values of controls are restored from VIEWSTATE unless u have disabled ViewState
0
 

Author Comment

by:x666xchange
ID: 7016846
Dear Naveen,

Well first of thank you very much for the very prompt reply. However, I request you to kindly re-consider the first 2 paras of my query. Especially the 2nd one that has the angle bracketed text. I hope those paras would clarify to you as to where my confusion lies. THANK YOU :-)
0
 

Author Comment

by:x666xchange
ID: 7016852
See the Page_Load event occurs when the page is loaded into the browser. That means at the client-end. So if I set the value of a particular label-control in the the Page_Load sub to say "ABC", is this statement actually occuring at the client side adn not at the server side. Or during Page_Load itself does the client meanwhile send a notification to the server which then does the setting of the value of the label.
0
 

Author Comment

by:x666xchange
ID: 7016857
lets say my script block is this way

<script language="VB" runat="server>
 sub Page_Load(obj as Object, E as EventArgs)
    << some_label >>.text = "XYZ"
 end sub
</script>
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:x666xchange
ID: 7016858
lets say my script block is this way

<script language="VB" runat="server>
 sub Page_Load(obj as Object, E as EventArgs)
    << some_label >>.text = "XYZ"
 end sub
</script>
0
 
LVL 23

Accepted Solution

by:
naveenkohli earned 80 total points
ID: 7016867
The confusion you have is at what time Page_Load occurs. It is not like <body> tag's onload or something. The loading on controls in ASP.Net occurs before the page is actually loaded on client side. As I mentioned earlier, Page_Load is event fired by framework and letting Page do any initiatlization it needs to do. After Page_Load there are more events like PreRender, SaveState and the end Render. During rendering, all the controls on the page, emit their respective HTML tags to show in the page.
Client does not participate during this process. Client participation starts when you start making changes or start using the controls. Then post backs happen. Otherwise everything happens on server side. Only thing that client initiates is the HTTP request meaning entering page url in browser. After that its all ASP.Net framework till page has been renderd.
0
 

Author Comment

by:x666xchange
ID: 7018251
Dear Naveen,

I wasn't able to check in detail ur most recent comment in detail when it appeared on this page on Friday coz I had checked my intimation main on Friday night.

But then after having gone through it much later in the evening ( that bought me time to once again go through my reference materials a bit more closely ), on Saturday I can say that in a way I had a similar hunch about when Page_Load occurs as has been put by you in ur comment in the following words: "loading on controls in ASP.Net occurs << before the page is actually loaded on client side >>. As I mentioned earlier, Page_Load is event fired by framework ".

Of particular interest to me are your words that I have bracketed in angle-brackets. I guess that was the hunch I had and the area that I was looking for re-confirmation from ur end. I feel relieved now that I was thinking in the right direction, thought I wasn't 100% sure. The confusion was because the reference material stated that the Page_Load even is fired when the page is loaded in the browser. Mark words "loaded in the browser". That's what really stumped me.

Thank you very much for your very valuable insight, help and patience. I greatly respect your knowledge and experience.

In the end, I request you to kindly have a look to a more recent query I posted on the concept of VIEWSTATE itself. Not the one that u had responded to, prior to that one title "ASP.NET - Query on ViewState".
0
 

Author Comment

by:x666xchange
ID: 7018254

Please check my query titled "ASP.NET - Query on ViewState"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now