There may be a better way, but javascript is not my strong point. The example below will fire an OnClick button event of an invisible button when the user presses ENTER (when the textbox has focus).
<asp:Button ID="button" runat="server" onclick="button_Click" style="display:none;" /> don't set visible=false (the button wont get rendered)
</script>Add to codebehind:
textbox.Attributes["onKeyDown"] = "javascript: if (TestForReturn()) document.all.button.click();";
If you're using a master page, do a view source to get the client button id and replace all.button.click with all.the client button id.click. Or in the code behind you can build the attribute string using button.ClientId.
Hope this helps... ~Rick
Please mark the post as ANSWER if it helps you
Disclaimer: Just my opinion. Not my employer or anyone else....
Rick Matthys
Contributor
2794 Points
406 Posts
Re: Autocomplete without web service..can we do that?
Feb 06, 2009 07:00 AM|LINK
There may be a better way, but javascript is not my strong point. The example below will fire an OnClick button event of an invisible button when the user presses ENTER (when the textbox has focus).
Add to aspx page:
<script type="text/javascript" language="javascript"> function TestForReturn() { if (event.keyCode == 13) { event.cancelBubble = true; event.returnValue = false; return true; } return false; }If you're using a master page, do a view source to get the client button id and replace all.button.click with all.the client button id.click. Or in the code behind you can build the attribute string using button.ClientId.
Hope this helps... ~Rick
Disclaimer: Just my opinion. Not my employer or anyone else....