I have a textbox
whose input is being handled by jQuery.
$('input.Search').bind("keyup", updateSearchTextbox);
When I press Enter
in the textbox, I get a postback, which messes everything up. How can I trap that Enter and ignore it?
(Just to preempt one possible suggestion: The textbox has to be an <asp:textbox ... />
- I can't replace it with an <input ... />
.)
Your browser is automatically submitting the form when you press enter. To cancel this, add return false to your updateSearchTextBox function.
if that doesn't work, try this:
<script language="JavaScript">
function disableEnterKey(e)
{
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
return (key != 13);
}
</script>
And in your codebehind:
textbox.Attributes.Add("OnKeyPress","return disableEnterKey(event)");
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