When I enter a keyword and want to press the Enter key, I can search. However, because there are other buttons on the page, this is not my search button by default. I searched for some solutions online, the most is the following method:
In Asp.net, how do I press enter to trigger the event of the specified button?
Hypothesis:
<Asp: textbox id = "tbinput" runat = "server" width = "240px"> </ASP: textbox>
<Asp: button id = "btnok" runat = "server" borderwidth = "1px" bordercolor = "Purple" borderstyle = "solid" text = "search site"> </ASP: button>
Solution:
On the. ASPX page, add:
<Script language = "JavaScript">
Function submitkeyclick (button)
{
If (event. keycode = 13)
{
Event. keycode = 9;
Event. returnvalue = false;
Document. All [button]. Click ();
}
}
// -->
</SCRIPT>
Add the following in the page_load event:
Tbinput. Attributes. Add ("onkeydown", "submitkeyclick ('btnok ');");
But I added it to my code and found that my function was not implemented. Why?
The reason is that I used the template page master, so after the page is translated into the HTML code of the client, my button name has changed,
Changed from bt_search to ctl00 $ contentplaceholder1 $ bt_search
Therefore, only the background code is changed to tbinput. Attributes. Add ("onkeydown", "submitkeyclick ('ctl00 $ contentplaceholder1 $ bt_search ');");
In this way, the code will work normally.