Avatar of Lawrence Avery
Lawrence AveryFlag for United States of America

asked on 

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?
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Miguel Oz
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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
Avatar of Lawrence Avery

ASKER

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?
Avatar of Lawrence Avery

ASKER

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.
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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.
Avatar of Lawrence Avery

ASKER

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.
http://devproconnections.com/aspnet/detect-control-changes
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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).
Avatar of Lawrence Avery

ASKER

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
https://msdn.microsoft.com/en-us/library/ms972976.aspx
Avatar of Lawrence Avery

ASKER

I looked at the interface IPostBackDataHandler and indicates it uses the ViewState -
see
https://msdn.microsoft.com/en-us/library/system.web.ui.ipostbackdatahandler(v=vs.110).aspx

now I am confused.   because if you look article:
https://msdn.microsoft.com/en-us/library/ms972976.aspx 

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.
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo