Solution to binding TextBox carriage return event in asp.net _ Practical tips

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.