Textbox and OnTextChanged

Discussion in 'ASP .Net' started by MattB, Sep 27, 2005.

  1. MattB

    MattB Guest

    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
     
    MattB, Sep 27, 2005
    #1
    1. Advertising

  2. MattB

    BPSmith Guest

    Do you have to round it? What type is it, an integer?
     
    BPSmith, Sep 27, 2005
    #2
    1. Advertising

  3. MattB

    Scott M. Guest

    You don't have AutoPostBack set to True for these controls do you?


    "MattB" <> wrote in message
    news:...
    > 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
     
    Scott M., Sep 27, 2005
    #3
  4. MattB

    MattB Guest

    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" <> wrote in message
    > news:...
    >
    >>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

    >
    >
    >
     
    MattB, Sep 27, 2005
    #4
  5. MattB

    Scott M. Guest

    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" <> wrote in message
    news:...
    >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" <> wrote in message
    >> news:...
    >>
    >>>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

    >>
    >>
     
    Scott M., Sep 29, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    6
    Views:
    767
    Henri
    Aug 6, 2004
  2. Mark Siffer
    Replies:
    3
    Views:
    5,853
    Karl Seguin
    Mar 30, 2005
  3. =?Utf-8?B?UGF1bA==?=

    Textbox with OnTextChanged Event

    =?Utf-8?B?UGF1bA==?=, Jun 14, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    4,054
    =?Utf-8?B?TUFDSCBJSQ==?=
    Jun 14, 2006
  4. Replies:
    0
    Views:
    551
  5. Paul

    Textbox and onTextChanged Event

    Paul, Jun 14, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    257
    Balasubramanian Ramanathan
    Jun 14, 2006
Loading...

Share This Page