Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

AutoPostBack and Multiple Controls (ASP.Net)

OK guys a slightly sticky one for you.

When I click a button immediately after changing a text box with AutoPostBack enabled I only get the textbox_textchanged event and not the button's click event.

If I click outside the box, then click the button I get both events in two separate postbacks.

Is this intended behaviour or have I coded something wrong?  Is it possible to get two events (or more) in one postback?  If not, what determines which event has precedence?

Thanks,

Tom

Thomas David Baker
Monday, July 21, 2003

Short answer: Expected behavior, given the UI medium. You're hitting a leaky abstraction.

Long answer: The idea that you will always flawlessly get every event is out the window when you use the web. The browser is involved. The blur of the text box starts the post, but before it even gets started, your click on the button cancels it and starts a new one. In the case where you're clicking outside, things are happening fast enough for you to get both events (which tells me you're testing against localhost; postbacks are generally going to be 1 second+ over the 'net).

Brad Wilson (dotnetguy.techieswithcats.com)
Monday, July 21, 2003

In other words I want autopostback only on my submit button and a few other special cases? 

I also hate the way focus flies off somewhere else when it happens so that tabbing through the 3-item form and then submitting is just not possible.

The application I'm working on was not written by me and they've got AutoPostBack on every form item throughout (I think).  What a lovely mess to sort out.

Thomas David Baker
Tuesday, July 22, 2003

Submit buttons don't need to have auto-postback enabled. They are devices specifically for the purpose of posting back. :)

Brad Wilson (dotnetguy.techieswithcats.com)
Tuesday, July 22, 2003

*  Recent Topics

*  Fog Creek Home