Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Textbox and OnTextChanged

Reply
Thread Tools

Textbox and OnTextChanged

 
 
MattB
Guest
Posts: n/a
 
      09-27-2005
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
 
Reply With Quote
 
 
 
 
BPSmith
Guest
Posts: n/a
 
      09-27-2005
Do you have to round it? What type is it, an integer?

 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      09-27-2005
You don't have AutoPostBack set to True for these controls do you?


"MattB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
MattB
Guest
Posts: n/a
 
      09-27-2005
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

Scott M. wrote:
> You don't have AutoPostBack set to True for these controls do you?
>
>
> "MattB" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>>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

>
>
>

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      09-28-2005
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.




"MattB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
> Scott M. wrote:
>> You don't have AutoPostBack set to True for these controls do you?
>>
>>
>> "MattB" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>>>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

>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox OnTextChanged Inside a Datalist hooterbite@yahoo.com ASP .Net 0 01-02-2007 05:28 PM
Textbox with OnTextChanged Event =?Utf-8?B?UGF1bA==?= ASP .Net 2 06-14-2006 03:38 PM
Textbox and onTextChanged Event Paul ASP .Net Web Controls 1 06-14-2006 03:24 PM
Retreiving old value from WebControls.TextBox with OnTextChanged Mark Siffer ASP .Net 3 03-30-2005 04:38 PM
textbox's state does not persist if onTextChanged not defined Henri ASP .Net 6 08-06-2004 02:08 PM



Advertisments