Method 1
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 ');");
S
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');"); then the code will work normally.
Method 2
Detach a button using <asp: Panel>
<Asp: imagebutton id = "getbackpwd" runat = "server" skinid = "getbackpwd" onlick = "getpwd"/>
<Asp: Panel id = "panlogin" runat = "server" defaultbutton = "login">
<Asp: textbox id = "txbusername" runat = "server"> </ASP: textbox>
<Asp: textbox id = "txbpwd" runat = "server" textmode = "password"> </ASP: textbox>
<Asp: imagebutton id = "login" runat = "server" skinid = "login" onclick = "login_click"/>
<Asp: imagebutton id = "register" runat = "server" skinid = "register" onclick = "Reg">
</ASP: Panel>
In this way, the carriage return only triggers the login_click event.
Because pane's defaultbutton = "login"