Re: Enter in textbox causes bad postback

Discussion in 'ASP .Net' started by vMike, Sep 22, 2004.

  1. vMike

    vMike Guest

    "Tony Hedge" <> wrote in message
    news:...
    > Hello,
    > I can briefly explain without providing any code, it's a simple NET 1.1

    web
    > project.
    >
    > I have a web form with a textbox A and button A (in a table row), and
    > textbox B and button B (in a second table row). The textboxes are of type
    > asp:Textbox and buttons are asp:Button. Autopostback=false for textboxes.
    > Click event used for the buttons.
    >
    > When user types in text in textbox B and hits Enter, the click event for
    > button A fires!!! Why, what is causing this to happen? I would like some
    > way to make button B fire instead, so I set the tabindex attributes on

    each
    > of the 4 controls above to try and provide that functionality but it

    didn't
    > work. the event for button A always fires when I ht enter.
    >
    > When I added textbox C and button C, etc... the same darn thing!!! How

    can
    > I at least turn off this behavior so that when Enter is hit no postback
    > occurs? I set autopostback to false for the textboxes but this didn't do
    > anything.
    >
    > Thanks in advance- Hedge


    Try something like this.
    <script language="javascript">
    function testForEnter()
    {
    if (event.keyCode == 13)
    {
    event.cancelBubble = true;
    event.returnValue = false;
    }
    }
    </script>
     
    vMike, Sep 22, 2004
    #1
    1. Advertising

  2. Hi vMike,

    My fallback was to do what you suggested, thanks for the good code snippet.

    I'm still thinking for a non client side solution, until I am thoroughly
    beaten. (Won't take long at this rate.. :))

    Thanks - Hedge

    "vMike" wrote:

    >
    > "Tony Hedge" <> wrote in message
    > news:...
    > > Hello,
    > > I can briefly explain without providing any code, it's a simple NET 1.1

    > web
    > > project.
    > >
    > > I have a web form with a textbox A and button A (in a table row), and
    > > textbox B and button B (in a second table row). The textboxes are of type
    > > asp:Textbox and buttons are asp:Button. Autopostback=false for textboxes.
    > > Click event used for the buttons.
    > >
    > > When user types in text in textbox B and hits Enter, the click event for
    > > button A fires!!! Why, what is causing this to happen? I would like some
    > > way to make button B fire instead, so I set the tabindex attributes on

    > each
    > > of the 4 controls above to try and provide that functionality but it

    > didn't
    > > work. the event for button A always fires when I ht enter.
    > >
    > > When I added textbox C and button C, etc... the same darn thing!!! How

    > can
    > > I at least turn off this behavior so that when Enter is hit no postback
    > > occurs? I set autopostback to false for the textboxes but this didn't do
    > > anything.
    > >
    > > Thanks in advance- Hedge

    >
    > Try something like this.
    > <script language="javascript">
    > function testForEnter()
    > {
    > if (event.keyCode == 13)
    > {
    > event.cancelBubble = true;
    > event.returnValue = false;
    > }
    > }
    > </script>
    >
    >
    >
     
    =?Utf-8?B?VG9ueSBIZWRnZQ==?=, Sep 22, 2004
    #2
    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. Xavier Osa
    Replies:
    0
    Views:
    642
    Xavier Osa
    Jan 9, 2004
  2. =?Utf-8?B?RGVtZXRyaQ==?=

    RE: Enter in textbox causes bad postback

    =?Utf-8?B?RGVtZXRyaQ==?=, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    624
    =?Utf-8?B?VG9ueSBIZWRnZQ==?=
    Sep 22, 2004
  3. =?Utf-8?B?VG9ueSBIZWRnZQ==?=

    Enter in textbox causes bad postback

    =?Utf-8?B?VG9ueSBIZWRnZQ==?=, Sep 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    377
    =?Utf-8?B?VG9ueSBIZWRnZQ==?=
    Sep 22, 2004
  4. rantingrick
    Replies:
    44
    Views:
    1,230
    Peter Pearson
    Jul 13, 2010
  5. HopfZ
    Replies:
    0
    Views:
    576
    HopfZ
    Aug 28, 2006
Loading...

Share This Page