Prevent Web Form from posting back

  • Thread starter Thread starter marcia
  • Start date Start date
M

marcia

In a Web Form with a Button and a TextBox, when I type
some characters in the TextBox (AutoPostBack == false) and
then hit the Enter key on the keyboard, the Web Form goes
to the server (as though I had pressed the Button). I want
the Form to go to the server when the Button - and not the
Enter key - is pressed.

???
 
That is the browser behavior.
You can avoid this but not having submit button (input type="submit").
Instead have a regular button (input type="button").


George.
 
My button needs to be an ASP.NET (Web Form) Button. Is
there a solution in this situation?
 
Here is the Browser rule (which is not related to ASP.NET at all ).

If user pressed enter then FORM is submitted if there is type="SUBMIT"
button. Or type="IMAGE" is present in the FORM.

So instead of WebControl button add HtmlControl button (which is under HTML
tab in the toolbox).

Then give it a try.


George.
 
Back
Top