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.
Set UseSubmitBehavior="False" on your Buttons. This disables the "AutoPostback" on Enter.
The postback on submit button can be avoided by giving return=false in the event handler function as below.
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.
I would prefer the second if i wanted to prevent Postbacks on Enter completely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With