Intro:
In the ASP.net page, the index of the TextBox is 1 (or n), followed by the Submit button index of 2 (N+1), the cursor is in the textbox, and the auto focus moves after the carriage return to the button on the back, triggering the button's Click event.
However, when you access a Web page in the Lyncplus client, you experience a failure of the submit event of the TextBox control carriage return AutoComplete button (which should be the automatic focus of switching).
Because the server-side TextBox control does not provide events such as onkeypress or onkeydown, it is not possible to write a background code for the carriage return event to invoke the Click event of the button button.
then the Internet to find the relevant introduction, the final solution to the following two problems:
(i) Implementation of the TextBox control carriage return event to execute the JS code to control the page element value.
(b) Implement the server-side C # code to implement the related functions by implementing the Click event of the server-side control in the TextBox control carriage return event.
specifically implemented as follows:
Registering and triggering a server-side TextBox control carriage return Event
1.PageLoad Event code:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
MESSAGETXT.ATTRIBUTES.ADD ("onkeypress", "Entertextbox ()");
MESSAGETXT.ATTRIBUTES.ADD ("onkeydown", "Entertextbox ()");
}
2.javascript Code:
Copy Code code as follows:
<script language= "JavaScript" >
function Entertextbox () {
if (Event.keycode = && document.all["messagetxt"].value!= "")//press ENTER, and the text box has a value
{
$ ("#<%=hidkeywords.clientid%>"). Val ($ ("#<%=messagetxt.clientid%>"). Val (). replace (/[^\U0000-\U00FF] /g,
Function ($) {
Return Escape ($). Replace (/(%u) (\w{4})/gi, "& #x $;")
}));
}
}
</script>
Second, the TextBox control carriage return event invokes the Service Side button control Click event
1.PageLoad event code: Ditto.
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
MESSAGETXT.ATTRIBUTES.ADD ("onkeypress", "Entertextbox ()");
MESSAGETXT.ATTRIBUTES.ADD ("onkeydown", "Entertextbox ()");
}
2.javascript Code: Note The original DOM object Fetch button is not available using jquery.
Copy Code code as follows:
<script language= "JavaScript" >
function Entertextbox () {
var button = document.getElementById (' <%=btnSearch.ClientID%> ');//Get the Page object for the server-side control
if (Event.keycode = 13)//press ENTER
{
Button.Click ();
Event.returnvalue = false;
}
} </script>