Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net page enter key causing post back

I have an aspx page that postsback when it should not. there are two text boxes, two listboxes and two buttons on the page. if at any-point the enter key is pressed the first button is given focus and "clicked" resulting in a loss of selection within the listboxes.

How do I disable this? There are tons of tutorials on how to capture the enter button and execute a method but I could not find one on how to simply disable the neat "let me grab the first button I find and click it" feature mentioned above.

like image 904
George Avatar asked Nov 17 '10 22:11

George


People also ask

How can we prevent postback on Enter key press in asp net?

Set UseSubmitBehavior="False" on your Buttons. This disables the "AutoPostback" on Enter.

How can stop post back in asp net?

The postback on submit button can be avoided by giving return=false in the event handler function as below.

Which control is used to initiate the post back automatically?

ASP.NET generates the _doPostBack() function automatically, provided at least one control on the page uses automatic postbacks. Any Control that has its AutoPostBack Property set to true is connected to the _doPostBack() function using the onclick or onchange attributes.


1 Answers

  • You could set the DefaultButton on the Form or a Panel. This way you have full control what happens.
  • Set UseSubmitBehavior="False" on your Buttons. This disables the "AutoPostback" on Enter.

I would prefer the second if i wanted to prevent Postbacks on Enter completely.

like image 198
Tim Schmelter Avatar answered Sep 29 '22 20:09

Tim Schmelter