|
-
Jan 17th, 2005, 04:31 PM
#1
Thread Starter
Addicted Member
Perform action when user presses <Enter> on keyboard.
I have this simple search form and would like for the search button action to act when the user presses the <enter> key on the keyboard instead of having to click on the search button.
Can someone please tell me how to do this. I see there is an AccessKey button to associate a keyboard shortcut but do not know what value to place in there if that is the right solution.
Any help would be appreciated.
Thanks.
-
Jan 18th, 2005, 12:23 PM
#2
Fanatic Member
Re: Perform action when user presses <Enter> on keyboard.
prob the best way is to have only 1 button, because once you hit enter the button will br triggered.
-
Jan 18th, 2005, 12:53 PM
#3
Frenzied Member
Re: Perform action when user presses <Enter> on keyboard.
Code:
<asp:textbox id="txtSearch" onKeyUp="__doSearchReturn()" runat="server"></asp:textbox> <asp:button id="btnSearch" text="Search" runat="server"></asp:button>
<script language="JavaScript">
function __doSearchReturn(e)
{
if(e.keyCode)
{//ie
if(e.keyCode == 13){__doPostBack('btnSearch','');}
}
else
{//n4
if(e.which == 13){__doPostBack('btnSearch','');}
}
}
</script>
something like that....
Magiaus
If I helped give me some points.
-
Jan 18th, 2005, 01:42 PM
#4
Addicted Member
Re: Perform action when user presses <Enter> on keyboard.
Magiaus
Do you know what the equivalent for e.which is in Netscape 7? It doesn't seem to like it.
-
Jan 18th, 2005, 02:27 PM
#5
Thread Starter
Addicted Member
Re: Perform action when user presses <Enter> on keyboard.
Thanks again for answering Magiaus, I entered it in just like you have it there, but it still doesnt seem to work. Nothing happens.
Am I missing something?
-
Jan 18th, 2005, 02:28 PM
#6
Thread Starter
Addicted Member
Re: Perform action when user presses <Enter> on keyboard.
Oh, and 'OnKeyUP' doesnt seem to be recognized, it tells me: Could not find any attribute 'onKeyUp' of element 'Textbox'.
And one other thing is that the button is an <asp:imagebutton> if that makes any difference.
And to Strider:
I do only have one button, is there a property I am not setting?
-
Jan 18th, 2005, 02:39 PM
#7
Thread Starter
Addicted Member
Re: Perform action when user presses <Enter> on keyboard.
Okay, i found the solution, by searching the internet.
Simply put this line of code in your OnLoad event in your code-behind:
Page.RegisterHiddenField("__EVENTTARGET", "btnSearch")
and voila it works.
Thanks again everyone for helping me out.
Here is the page i found the solution on:
http://www.developer.com/net/asp/article.php/1594521
-
Jan 19th, 2005, 11:35 AM
#8
Frenzied Member
Re: Perform action when user presses <Enter> on keyboard.
Don't know about Navigator 7 I just checked in my ye old JavaScript book from like 5 years ago lol.
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|