Asp.NET Page Life Cycle - Raise Postback Event

My understanding there are two flavors of postback events.

1) The first is a changed event. The event fires when some piece of data is changed between postbacks. Example is a DropLists - SelectedIndexChange event or the Textbox's textChanged event.

2) The other flavor of postback is the raised event. An example is the button click.

Tell  me if my understanding is right for the changed event - the postback data is compared to the viewstate data to cause a change event to fire.

How does raised event - like the button click get recogonized on the server side?
Lawrence AverySystem DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSenior Software EngineerCommented:
1) Change event firing decision is done in browser (Control is mapped to Html select that supports onchange event).
2) Button typically submits the form to the server.
In general the server receives any post back browser request and it decides whether the request is done by a particular analyzing the request parameters.
You can check it your yourself by adding the following code to your page load event:
string eventTarget = Request.Params.Get("__EVENTTARGET");

Open in new window

eventTarget will contain your target button or control id in general
Lawrence AverySystem DeveloperAuthor Commented:
You're saying in regards to Button click, the button and eventhandler name  will added to eventTarget so server will execute the correct event handler?

In regards to Change event, will the control id and its eventhandler name be assigned to eventTarget also?
Lawrence AverySystem DeveloperAuthor Commented:
I guess what I am saying is how does the client side indicate -- for instance say --a  dropdownlist control changed it selection and also how does the client tell the server what method to call on selection change?
These are nonpostback events.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Miguel OzSenior Software EngineerCommented:
The client side sends the information as part of the Request. This is already done by the code generated by the server (JavaScript) and totally transparent to you. Just do a view source or use IE developer tools (press F12 - DOM tab)
For example, in the dropdown list example, this is mapped to a HTML select  element and ASP.NET generates the onchange event that contains a call to submit the page (form) to server. Then the server checks the event target and argument and calls page_load and the appropriate control event.
Lawrence AverySystem DeveloperAuthor Commented:
I understand the event target and argument  is the form variable that holds the name of the control which issued the submit.   But what about events on the page that do not issue the submit.

I am saying on the aspx page we
1st)     select a item in dropdownlist which doesn't submit the page
2nd)  then subsequently hit a button to submit the form.

So in this case event target is the submit button not the dropdownlist. So how does the aspx page on server side know that it must process also the change event when selecting an item in the dropdownlist?

To me there are 2 events here the click event and the change event. How does the server know about  both events  when event targets holds only one event?  At least is what I think it does.

See this and read the bottom of it.
Miguel OzSenior Software EngineerCommented:
Your case is different because the dropdown list is not posting back to server. Even though the button submits the page, all OTHER controls are recreated in the server either by using view state or using the current selected option if view state is false.
From client  (browser) there are two events (change and click), from server perspective there is one event (button click).
Lawrence AverySystem DeveloperAuthor Commented:
I don't see how from server perspective there is one event(button click) when the server must execute an event handler for the change event.  I am going to research a little more and get back to this in a couple of days.  Under  Understanding ASP.NET View State  msdn article - Stage 5 - Raise Postback Event. in particular it says raise postback event stage does not use the View State.
So how does it do a comparison of old value to new value on change event?

See link
Lawrence AverySystem DeveloperAuthor Commented:
I looked at the interface IPostBackDataHandler and indicates it uses the ViewState -

now I am confused.   because if you look article: 

read Stagee 5 section  - Raise Postback Event - last paragragh-
It says:
Since this stage inspects postback data to determine if any events need to be raised, the stage only occurs when the page has been posted back. As with the load postback data stage, the raise postback event stage does not use view state information at all. Whether or not an event is raised depends on the data posted back in the form fields.
Miguel OzSenior Software EngineerCommented:
The postback itself does not use view state unless the control requires it in order to keep state.
Web forms is very messy and you are not the only one having to deal with this challenge. Suffice to say that in reality the postback is a form submit in disguise and the server event click is just a convenience  that ASP.NET offers to emulate winform event handling so that desktop developers can make a transition to web forms.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.