Textbox and OnTextChanged

M

MattB

Hi. I'm working on an intranet application that requires a user to input
information about themselves. I have a user control with a couple of
textboxes that I want the user to enter their weight into. One is for
Lbs and one is for kg and I'm using the OnTextChanged event to populate
the other control if one is filled in (converting between kg and Lbs).

It works, but when one TextBox is changed and it sets the other's value,
the second TextBox's OnTextChanged event fires too. I'd like to force
only the one one being typed into to fire because with rounding
involved, it may change the text just entered.

So basically, I want to ensure only one postback when the text is
changed in a TextBox and I'm currently getting two because both controls
fire their OnTextChanged events.

Thanks!

Matt
 
M

MattB

I do. I thought it was necessary, or does that event work without it...

OK, I just tried it and without AutoPostBack=True, the event doesn't
fire at all. Seems like I need it.

Thanks,
Matt
 
S

Scott M.

The TextChanged event is registered as having happened at the client level,
but the actual event handler code does not fire until the form is posted
back to the server (remember, event handlers are server-side code and
changing the text happens at the client-level).

So, if you have AutoPostBack turned off for both of the textboxes (which is
the default setting), a user can change the text in one or both of the
textboxes and nothing will happen until the form is submitted to the
server.... then the TextChanged event handler for one or both of the
textboxes will fire, but there will just be one postback.

The point of AutoPostBack is that *if* the control is manipulated in any way
(like changing the text in a textbox), then that action will cause a
postback. So, if you have this turned on for both textboxes, changing
either of them will cause a postback, changing both of them will cause 2
postbacks.

So, the answer is to have AutoPostBack turned off for both of them and when
the user is ready for the conversion to happen, they can just hit a Submit
button that will cause one postback to the server and whichever textbox has
been changed will then run its TextChanged event hander.
 

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,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top