TexChanged event and Click event confusion

  • Thread starter Thread starter Tommy
  • Start date Start date
T

Tommy

Sometimes, I use "TextBox_TextChanged" event to auto fill in other text box
once user tab out from the search box.
i.e. connect to database and use the field to search out record and then
fill in other text box.
However, I also use a "Update" button to update the database once click it.
The problem is that I type something in
text box and then click button to update. The TextBox_TextChanged event is
trigger before the button click event is trigger.
How to solve this problem? Thanks.
 
Hi,

the event that is by the postbacking control (which causes the postback)
will be running last always. There's no way changing that. For TextBox the
TextChanged event is just signal of change in the state, while with Button
it is indication that this was clicked and a postback happened.

However, you certainly can put up a boolean flag which is set to true in
TextChanged, and check that in Button_Click and then do what needs to be
done based on it (e.g gives you knowledge if something was changed in the
TB).

It's also possible to develop a custom TextBox control which would indicate
the change in state earlier than on TextChanged event, however that's not
very helpful int his scenario, if I understand correctly.
 
If you mean onclick at client (browser), yes, it does but at server-side it
is the postbacking control whose event fires last. If you have TextBox on
the Page and a Button, you change the text and click Button, it is the
Button's Click event from those two which fires the last. If TextBox is
autopostbacking (AutoPostback=true), there should still be no problems as
then those happen as two totally separate steps.

See following Page lifecycle diagram. It covers also ASP.NET v20 but
important is to note that RaiseChangedEvents runs before RaisePostBackEvent
(it is the same in v1). TextChanged event is one of those changed events
while Button's Click is a postback event.

http://hydrate.typepad.com/leo/2004/08/the_aspnet_v20_.html
 

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

Back
Top