I have a problem with a page that has a logout button and textboxes - if someone types text into the textbox and then hits the enter key - it activates the logout button ?????
So I created a test page with one text box and a button and this seems to do exactly the same thing
Is the page
is the code behind
when I type ant text in the box and hit enter the logout button is triggered ???
How cam I stop this???
That's standard behavior for Web pages. When you press Enter the first Submit button will be accessed and the active form is submitted. The same is true on this form here for example. Textareas (ie. multi-line textboxes) can accept Enter though.
You can work around this with some JavaScript by effectively disabling the form submit unless you explictly click the button.
Something like this:
<form id="form1" onsubmit="formSubmit(false)" />
<input type="submit" name="btnSubmit" id="btnSubmit" onclick="formSubmit(true)" />
</form>
<script>
function formSubmit(force) {
if (!force)
return;
$("#form1").submit();
}
</script>
But I would really advise against that. Web Forms are expected to submit on Enter operations of textboxes, so when you change behavior you essentially break the Web...
+++ Rick ---