1. Bind the carriage return event on the page to the button
Copy Code code as follows:
function Entertextbox (e)
{
var msie = (document.all)? True:false;
var keycode;
if (!msie) keycode = window.event? E.keycode:e.which;
else keycode = E.keycode;
alert (keycode);
if (keycode==13 && document.getElementById (' <%=this.txtSearch.ClientID%> '). Value!= "")
{
Alert ("Test");
if (MSIE)
{
E.keycode = 9;
E.returnvalue = false;
}
document.getElementById (' <%=this.btnSearch.ClientID%> '). Click ();
}
}
2. Set the button client event in the OnPreRender event
Copy Code code as follows:
protected override void OnPreRender (EventArgs e)
{
TXTSEARCH.ATTRIBUTES.ADD ("onkeypress", "Entertextbox (event);")
}
It's done.
Reference articles:
Http://www.jb51.net/article/27713.htm
Original reference:
1. Bind all carriage return events on the page to a button
Copy Code code as follows:
<HEAD>
<script language= "JavaScript" >
function Entertextbox ()
{
if (Event.keycode = && document.all["TextBox1"].value!= "")
{
Event.keycode = 9;
Event.returnvalue = false;
document.all["Button1"].click ();
}
}
</script>
</HEAD>
<body onkeypress= "return Entertextbox ()" >
2. Different TextBox bindings different button
Copy Code code as follows:
<HEAD>
<script language= "JavaScript" >
function Entertextbox (button)
{
if (Event.keycode = 13)
{
Event.keycode = 9;
Event.returnvalue = false;
Document.all[button].click ();
}
}
</script>
</HEAD>
In the corresponding CS file
Binding TextBox Carriage Return event
TEXTBOXPORTOFDESTINATION.ATTRIBUTES.ADD ("onkeypress", "Entertextbox (' Buttonchoose ')");
TEXTBOXITEMNAME.ATTRIBUTES.ADD ("onkeypress", "Entertextbox (' Buttonadd ')");
Textboxcost_px. Attributes.Add ("onkeypress", "Entertextbox (' Buttonadd ')");
textboxcost_1x20. Attributes.Add ("onkeypress", "Entertextbox (' Buttonadd ')");
Web code:
Copy Code code as follows:
<fieldset>
<legend id= "Legenddetail" [Check the terms of the case]</legend>
<table>
<tr><td>
<asp:textbox id= "TextBox 1" runat= "Server" ></asp:TextBox></td>
</tr>
<tr>
<TD >
<asp:button id= "BTN" runat= "Server" onclick= "Btnquery_click"/></td>
</tr>
</table>
</fieldset>
This is the pattern. In textbox carriage return, call Btnquery_click