Why is a button Click event also called when a textbox TextChanged event is called???

Discussion in 'ASP .Net' started by S_K, Nov 7, 2007.

  1. S_K

    S_K Guest

    This is a weird problem..

    I have a page with a textbox and a button (along with a bunch of other
    stuff). Both the textbox and the button have their SEPERATE events
    defined for the textchanged and click events. When I change the text
    in the textbox the textchanged event is called as expected. But the
    button click event is also called!?

    Whats with that?!

    Can anybody help? This is driving me crazy!

    Thanks

    Steve
    S_K, Nov 7, 2007
    #1
    1. Advertising

  2. S_K

    bruce barker Guest

    Re: Why is a button Click event also called when a textbox TextChangedevent is called???

    possible reasons

    1) you hit enter/return after changing the text. this will cause the
    button to postback

    2) you don't have autopostback set on the textbox, so the postback only
    occurs when you hit the button.

    -- bruce (sqlwork.com)


    S_K wrote:
    > This is a weird problem..
    >
    > I have a page with a textbox and a button (along with a bunch of other
    > stuff). Both the textbox and the button have their SEPERATE events
    > defined for the textchanged and click events. When I change the text
    > in the textbox the textchanged event is called as expected. But the
    > button click event is also called!?
    >
    > Whats with that?!
    >
    > Can anybody help? This is driving me crazy!
    >
    > Thanks
    >
    > Steve
    >
    bruce barker, Nov 7, 2007
    #2
    1. Advertising

  3. S_K

    S_K Guest

    On Nov 7, 1:41 pm, bruce barker <> wrote:
    > possible reasons
    >
    > 1) you hit enter/return after changing the text. this will cause the
    > button to postback
    >
    > 2) you don't have autopostback set on the textbox, so the postback only
    > occurs when you hit the button.
    >
    > -- bruce (sqlwork.com)
    >
    >
    >
    > S_K wrote:
    > > This is a weird problem..

    >
    > > I have a page with a textbox and a button (along with a bunch of other
    > > stuff). Both the textbox and the button have their SEPERATE events
    > > defined for the textchanged and click events. When I change the text
    > > in the textbox the textchanged event is called as expected. But the
    > > button click event is also called!?

    >
    > > Whats with that?!

    >
    > > Can anybody help? This is driving me crazy!

    >
    > > Thanks

    >
    > > Steve- Hide quoted text -

    >
    > - Show quoted text -


    First, Thanks for responding.

    Second, The first possiblility makes sense. However, why would hitting
    the <ENT> or return key cause a button event to fire? Is there any way
    I can undo that?

    Thanks again.
    Steve
    S_K, Nov 7, 2007
    #3
  4. S_K

    LVP Guest

    <script language=javascript type=text/javascript>
    <!-- Script courtesy of http://www.web-source.net - Your Guide to
    Professional Web Site Design and Development
    function stopRKey(evt) {
    var evt = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement
    : null);
    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
    }

    document.onkeypress = stopRKey;
    -->
    </script>

    From http://www.web-source.net/javascript_disable_enter_key.htm by John
    Nitkowski

    "S_K" <> wrote in message
    news:...
    > On Nov 7, 1:41 pm, bruce barker <> wrote:
    >> possible reasons
    >>
    >> 1) you hit enter/return after changing the text. this will cause the
    >> button to postback
    >>
    >> 2) you don't have autopostback set on the textbox, so the postback only
    >> occurs when you hit the button.
    >>
    >> -- bruce (sqlwork.com)
    >>
    >>
    >>
    >> S_K wrote:
    >> > This is a weird problem..

    >>
    >> > I have a page with a textbox and a button (along with a bunch of other
    >> > stuff). Both the textbox and the button have their SEPERATE events
    >> > defined for the textchanged and click events. When I change the text
    >> > in the textbox the textchanged event is called as expected. But the
    >> > button click event is also called!?

    >>
    >> > Whats with that?!

    >>
    >> > Can anybody help? This is driving me crazy!

    >>
    >> > Thanks

    >>
    >> > Steve- Hide quoted text -

    >>
    >> - Show quoted text -

    >
    > First, Thanks for responding.
    >
    > Second, The first possiblility makes sense. However, why would hitting
    > the <ENT> or return key cause a button event to fire? Is there any way
    > I can undo that?
    >
    > Thanks again.
    > Steve
    >
    LVP, Nov 7, 2007
    #4
  5. S_K

    LVP Guest

    http://www.arraystudio.com/as-workshop/disable-form-submit-on-enter-keypress.html


    "S_K" <> wrote in message
    news:...
    > On Nov 7, 1:41 pm, bruce barker <> wrote:
    >> possible reasons
    >>
    >> 1) you hit enter/return after changing the text. this will cause the
    >> button to postback
    >>
    >> 2) you don't have autopostback set on the textbox, so the postback only
    >> occurs when you hit the button.
    >>
    >> -- bruce (sqlwork.com)
    >>
    >>
    >>
    >> S_K wrote:
    >> > This is a weird problem..

    >>
    >> > I have a page with a textbox and a button (along with a bunch of other
    >> > stuff). Both the textbox and the button have their SEPERATE events
    >> > defined for the textchanged and click events. When I change the text
    >> > in the textbox the textchanged event is called as expected. But the
    >> > button click event is also called!?

    >>
    >> > Whats with that?!

    >>
    >> > Can anybody help? This is driving me crazy!

    >>
    >> > Thanks

    >>
    >> > Steve- Hide quoted text -

    >>
    >> - Show quoted text -

    >
    > First, Thanks for responding.
    >
    > Second, The first possiblility makes sense. However, why would hitting
    > the <ENT> or return key cause a button event to fire? Is there any way
    > I can undo that?
    >
    > Thanks again.
    > Steve
    >
    LVP, Nov 7, 2007
    #5
  6. S_K

    LVP Guest

    http://www.felgall.com/jstip43.htm


    "S_K" <> wrote in message
    news:...
    > On Nov 7, 1:41 pm, bruce barker <> wrote:
    >> possible reasons
    >>
    >> 1) you hit enter/return after changing the text. this will cause the
    >> button to postback
    >>
    >> 2) you don't have autopostback set on the textbox, so the postback only
    >> occurs when you hit the button.
    >>
    >> -- bruce (sqlwork.com)
    >>
    >>
    >>
    >> S_K wrote:
    >> > This is a weird problem..

    >>
    >> > I have a page with a textbox and a button (along with a bunch of other
    >> > stuff). Both the textbox and the button have their SEPERATE events
    >> > defined for the textchanged and click events. When I change the text
    >> > in the textbox the textchanged event is called as expected. But the
    >> > button click event is also called!?

    >>
    >> > Whats with that?!

    >>
    >> > Can anybody help? This is driving me crazy!

    >>
    >> > Thanks

    >>
    >> > Steve- Hide quoted text -

    >>
    >> - Show quoted text -

    >
    > First, Thanks for responding.
    >
    > Second, The first possiblility makes sense. However, why would hitting
    > the <ENT> or return key cause a button event to fire? Is there any way
    > I can undo that?
    >
    > Thanks again.
    > Steve
    >
    LVP, Nov 7, 2007
    #6
  7. "S_K" <> wrote in message
    news:...
    > On Nov 7, 1:41 pm, bruce barker <> wrote:
    >> possible reasons
    >>
    >> 1) you hit enter/return after changing the text. this will cause the
    >> button to postback

    <...>
    > Second, The first possiblility makes sense. However, why would hitting
    > the <ENT> or return key cause a button event to fire? Is there any way
    > I can undo that?


    If you are using .NET 2.0, you can set the Button's UseSubmmitBehavior
    property to false.



    --
    Robert Dunlop
    ----------------
    http://www.directxzone.org
    http://rdunlop.spaces.live.com/
    Microsoft DirectX MVP 1998-2006
    Robert Dunlop, Nov 8, 2007
    #7
    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. jorge
    Replies:
    2
    Views:
    1,250
    jorge
    May 26, 2004
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,744
    Smokey Grindel
    Dec 2, 2006
  3. jorge
    Replies:
    1
    Views:
    403
    Teemu Keiski
    May 28, 2004
  4. jorge
    Replies:
    0
    Views:
    313
    jorge
    May 25, 2004
  5. jorge
    Replies:
    0
    Views:
    245
    jorge
    May 25, 2004
Loading...

Share This Page