GRRR! Pages submitting with Enter key, combined with .ASCX pages - help!

Discussion in 'ASP .Net' started by Mike Kingscott, Dec 5, 2003.

  1. Totally hacked off here. I've written a user control that contains a
    text box, a required field validator and a button (these being the
    cornerstone of a search facility), all as ASP.Net server controls. The
    user clicks the button, and server-side code does a redirect to a
    search page, appending the search expression to the URL.

    Great, I thought, let's move on. I then wrote an mailing list page
    which included the aforementioned user control, then another textbox,
    required field validator and button.

    So, I load up the page, click the "Submit Email Addy" button - and the
    search button required field validator kicks in. After research (on
    Google Groups, natch), I figure out that it forms part of the page.
    So, I disable the required field validator and it's viewstateenabled
    properties. Then, when the user clicks the button, I re-enable the req
    field validator, call Page.Validate(), and continue if things are ok.

    This, when applied to my buttons and text boxes appeared to work - but
    only if the buttons are clicked!!! If someone hits enter whilst in the
    text box, the page submits, which is not desired. I've written a page
    that, er, pages data with next/prev buttons. These buttons have their
    viewstate disabled so I can enable them each time the page loads. So,
    when the user hits enter in the text box, the whole page submits (the
    validator code doesn't get fired) and the prev\next buttons are
    disabled because that's their initial setting.

    After yet more research, I found some javascript code that disables
    the enter key in a text box, which works great... EXCEPT NOW, IF YOU
    HIT ENTER JUST WITH FOCUS ON THE BROWSER, IT STILL SUBMITS!!! And the
    search required field validator kicks in, which it most definitely
    shouldn't (unless it's being picked up as the first "submit" button in
    the page, yeah, that'd be it).

    So, as just alluded to, I did more research and found out about
    ASP.Net rendering ASP:button down to an <input type="submit"> control
    and that reacts to a Enter keystroke because it's on a form.

    In a nutshell: how do I a) stop the page from submitting JUST BY THE
    USER HITTING ENTER and b) have separate textboxes, req. field
    validators and buttons that act independently of each other?

    Oh yeah: All by server-side stuff, no Javascript...

    Thanks,

    Mike Kingscott
     
    Mike Kingscott, Dec 5, 2003
    #1
    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. thechaosengine
    Replies:
    2
    Views:
    478
  2. =?Utf-8?B?ZmFzZW5qb2Y=?=

    I don't want the enter key submitting a webform :'(

    =?Utf-8?B?ZmFzZW5qb2Y=?=, Apr 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    527
    =?iso-8859-1?Q?Yunus_Emre_ALP=D6ZEN_=5BMCP=5D?=
    Apr 19, 2005
  3. Phil
    Replies:
    2
    Views:
    5,084
  4. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    422
    Anders Matthiessen
    Jan 12, 2005
  5. M P
    Replies:
    1
    Views:
    504
Loading...

Share This Page