ASP.NET PostBack Question

M

Matthew Louden

I created simple ASP.NET web application to test how AutoPostBack property
in a web control works.

I set AutoPostBack property to be true of a web control. When I run the
application, here's the sequences when I step through the program:

1. Page loaded to the browser
2. Page_Load method is called with non-postback event
3. The user has certain actions on a control
4. Page_Load method is called with postback event
5. A control's event handler is called.

My question is why Page_Load method is called before a control's event
handler? i.e. Should step 4 and step 5 be reversed in order?

My understanding is ONE CONTROL EVENT causes ONE POSTBACK. Event is the
cause, and PostBack is the result. Am I wrong?? Thats why I think a
control's event handler should call first before Page_Load method.



Please advise. Thanks!




`
 
S

Sherif ElMetainy

Hello

The event handler didn't cause the post back, the user's browser did by
submitting the form.
The event took place in the browser then the user took the action for the
control.
Then the form is posted to the server.
Then event handler is executed to take appropriate action base on the event,
such as updating a database.
 
B

bruce barker

you have it slightly wrong. onload fires after all controls defined on page
have been created and their data loaded from the postback data if any.



browser requests page ->>

server
OnInit
OnLoad (form load)
OnPreRender
SaveViewState
Render
OnUnload
<<-- rendered page sent to browser

browser loads page
user clicks on something to do postback
browser posts form data --->

server
OnInit
LoadViewState
LoadPostBackData (loads controls with postback data)
OnLoad (form load)
RaisePostDataChangedEvent (controls raise data change event here)
RaisePostBackEvent (controls raise postback events here)
OnPreRender
SaveViewState
Render
OnUnload
<<-- rendered page sent to browser

browser loads page


you can see from the page create cycle, that OnInit is the last chance to
create dynamic controls that load postback data. OnPreRender is the last
chance to add/change controls that will actually render.

-- bruce (sqlwork.com)
 
A

amy amy

I have asp:label on the page,
on submit i am opening crystal report
and changing the label on the page also .but
some how its not changing the label text but it opens the crystal report


is postback help me to change the label text which i am changing in

sub onsubmit_click
label1.text = "done"

'open crystal report

end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top