PostBack NonPostBack Event order issue

Q

Q. John Chen

On a webForm, I have a DropDownList with AutoPostBack=true and I also
have couple textbox with AutoPostBack=false.

I am expect that the DropDownList's SelectedIndexChanged event being
handled after the textboxs' TextChanged event since this is the one
that cause the PostBack.

But I got the DropDownList's event first.

Reading the document, I noticed it only mention all the change event
are handled in NO particular order, the the CLICK event that CAUSE the
POST is processed. So I can't complain much but it would be nice the
see the any event that CAUSE the post is handled last.

John
 
N

Natty Gur

John Hi,

I'm little bit confused. ASP.NET post back architecture is build on two
hidden field that hold the control ID and optionally parameters that
cause post back. The server side now which control and event to call by
the hidden field that holds specific control ID thus just one event can
be call per post back. Each post back the page initialize and the PAGE
events are called before the request control event.

So I cant see how you can get events of combo box and textboxes on the
server side. You also mention that you set the textboxes autopostback to
false so they don't trigger any postback at all.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Q

Q. John Chen

Natty,

Thanks for the response, I may not user correct terms. Here is my
prolem w/ example.

On the webform, I have:
1. A dropdownlist/combo box - ddlOne, w/ AutoPostBack=true
2. A textbox - txtTwo, w/ AutoPostBack=false
Both controls have their event handlers:
ddlOne_SelectedIndexChanged, and
txtTwo_TextChanged.

I first enter some text in txtTwo. The TextChange is NOT fired
immediately because AutoPostBack is set to false. Then I select an
item from the ddlOne. And this CAUSE the POSTBACK.

Now look at the order of the events - ddlOne_SelectedIndexChanged is
alway before txtTwo_TextChanged.

I understand why ddlOne_SelectedIndexChanged happen first because
ddlOne is put one the form first. It DOESN'T MATTER who cause the
postback. Both events are StateChange event that implement the
IPostBackDataHandler interface. The runtime tracks the controls that
return true to LoadPostData and Invoke the RaisePostDataChangedEvent
in the order of the controls on the form.

So this is by design not a bug but a challenge for me. I want the
TextChanged event happen first because the ddlOne_SelectedIndexChanged
need the outcome the the text.

Or, is there any Event that I can be sure is the LAST event that I can
use?

Thanks again.

John
 
B

bruce barker

PreRender is the last event, where you can still change page rendering

-- bruce (sqlwork.com)
 
N

Natty Gur

Hi,

I think I understood you. the event order set by the control order in
page HTML. if you place combo and text box and the textbox is before the
listbox. the textbox event will fired first. change the order and the
listbox event will be fired first.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top