Help:How to avoid button click event when Enter key is press in a TextBox?

Discussion in 'ASP .Net' started by Jie, Oct 8, 2004.

  1. Jie

    Jie Guest

    Hi, All,
    I have a simple ASPX page that has one textbox, one linkbutton and one
    button. When I enter something on the textbox and press ENTER key, the
    button click event gets fired. What I want is the LinkButton click event
    gets fired. I wrote a java script to fire the LinkButton Click event in the
    onkeydown event of the textbox. But after the LinkButton click event is
    fired, the Button Click event is also fired. Can anybody help me to suppress
    the Button Click event in this situation? Thanks

    Jie
     
    Jie, Oct 8, 2004
    #1
    1. Advertising

  2. RE: Help:How to avoid button click event when Enter key is press in a

    You probably want to try this free control that lets you assign the button to
    fire when the user presses enter in a textbox:

    DefaultButtons Control

    http://www.metabuilders.com/Tools/DefaultButtons.aspx


    "Jie" wrote:

    > Hi, All,
    > I have a simple ASPX page that has one textbox, one linkbutton and one
    > button. When I enter something on the textbox and press ENTER key, the
    > button click event gets fired. What I want is the LinkButton click event
    > gets fired. I wrote a java script to fire the LinkButton Click event in the
    > onkeydown event of the textbox. But after the LinkButton click event is
    > fired, the Button Click event is also fired. Can anybody help me to suppress
    > the Button Click event in this situation? Thanks
    >
    > Jie
    >
    >
    >
     
    =?Utf-8?B?S2VuIENveCBbTWljcm9zb2Z0IE1WUF0=?=, Oct 8, 2004
    #2
    1. Advertising

  3. Xavier Pacheco, Oct 8, 2004
    #3
  4. Jie

    Jie Guest

    Re: Help:How to avoid button click event when Enter key is press in a

    Ken,
    Thanks for the reply. I don't think we will use a free control in our
    project. I am still looking for a way to fire the linkbutton click event. Do
    you have any other suggestions? Thanks again.

    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:...
    > You probably want to try this free control that lets you assign the button

    to
    > fire when the user presses enter in a textbox:
    >
    > DefaultButtons Control
    >
    > http://www.metabuilders.com/Tools/DefaultButtons.aspx
    >
    >
    > "Jie" wrote:
    >
    > > Hi, All,
    > > I have a simple ASPX page that has one textbox, one linkbutton and one
    > > button. When I enter something on the textbox and press ENTER key, the
    > > button click event gets fired. What I want is the LinkButton click event
    > > gets fired. I wrote a java script to fire the LinkButton Click event in

    the
    > > onkeydown event of the textbox. But after the LinkButton click event is
    > > fired, the Button Click event is also fired. Can anybody help me to

    suppress
    > > the Button Click event in this situation? Thanks
    > >
    > > Jie
    > >
    > >
    > >
     
    Jie, Oct 8, 2004
    #4
  5. Re: Help:How to avoid button click event when Enter key is press i

    The source code for that control is freely available, so you could adapt it
    to your project quite easily without using the compiled version.


    "Jie" wrote:

    > Ken,
    > Thanks for the reply. I don't think we will use a free control in our
    > project. I am still looking for a way to fire the linkbutton click event. Do
    > you have any other suggestions? Thanks again.
    >
    > "Ken Cox [Microsoft MVP]" <> wrote in message
    > news:...
    > > You probably want to try this free control that lets you assign the button

    > to
    > > fire when the user presses enter in a textbox:
    > >
    > > DefaultButtons Control
    > >
    > > http://www.metabuilders.com/Tools/DefaultButtons.aspx
    > >
    > >
    > > "Jie" wrote:
    > >
    > > > Hi, All,
    > > > I have a simple ASPX page that has one textbox, one linkbutton and one
    > > > button. When I enter something on the textbox and press ENTER key, the
    > > > button click event gets fired. What I want is the LinkButton click event
    > > > gets fired. I wrote a java script to fire the LinkButton Click event in

    > the
    > > > onkeydown event of the textbox. But after the LinkButton click event is
    > > > fired, the Button Click event is also fired. Can anybody help me to

    > suppress
    > > > the Button Click event in this situation? Thanks
    > > >
    > > > Jie
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?S2VuIENveCBbTWljcm9zb2Z0IE1WUF0=?=, Oct 8, 2004
    #5
  6. Jie

    JG Guest

    Yes, I did it but it did not help. It did suppress the button click event
    but it also suppress my key press that is the character I enter didd not
    show up in the textbox. Thanks.


    "Xavier Pacheco" <xavier@_nospam_xapware.com> wrote in message
    news:...
    > Did you specify "return false" in the JavaScript?
    >
    > "javascript:YourFunction();return false;";
    >
    > --
    > Xavier Pacheco
    > Xapware Technologies Inc
    >
    > manage your projects: www.xapware.com/ActiveFocus.htm
    > the blog: www.xavierpacheco.com/xlog
    > the book: www.amazon.com/exec/obidos/ASIN/0672324431//xavierpacheco-20
     
    JG, Oct 9, 2004
    #6
  7. Jie

    Jie Guest

    HI, Xavier,
    It works when I use "javascript: return YourFunction();"
    In the function YourFunction(), I can return true or false.
    Thanks for help.


    "Xavier Pacheco" <xavier@_nospam_xapware.com> wrote in message
    news:...
    > Did you specify "return false" in the JavaScript?
    >
    > "javascript:YourFunction();return false;";
    >
    > --
    > Xavier Pacheco
    > Xapware Technologies Inc
    >
    > manage your projects: www.xapware.com/ActiveFocus.htm
    > the blog: www.xavierpacheco.com/xlog
    > the book: www.amazon.com/exec/obidos/ASIN/0672324431//xavierpacheco-20
     
    Jie, Oct 9, 2004
    #7
  8. Xavier Pacheco, Oct 9, 2004
    #8
    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. Natty Gur
    Replies:
    0
    Views:
    590
    Natty Gur
    Jun 30, 2003
  2. Chad Z. Hower aka Kudzu
    Replies:
    1
    Views:
    683
  3. TS
    Replies:
    5
    Views:
    14,545
    Jeffrey Tan[MSFT]
    Nov 29, 2005
  4. Max2006
    Replies:
    2
    Views:
    1,593
    Walter Wang [MSFT]
    Sep 19, 2007
  5. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    414
    Anders Matthiessen
    Jan 12, 2005
Loading...

Share This Page