Introduction:
In the page, the index of the textbox is 1 (or n), and the subsequent submission button is 2 (n+1). The cursor is in the textbox. After pressing, the automatic focus moves to the subsequent button, which will trigger the button click event.
However, when accessing the web page in the Lyncplus client, I encountered the situation where the TextBox control Enter autocomplete button's submission event failed (it should be that the focus should be automatically switched).
Since the TextBox control on the server does not provide events such as OnKeyPress or OnKeyDown, it is also impossible to write background code for the carriage return event to call the Button button click event.
So I searched for relevant introductions online and finally solved the following two problems:
(1) Implement the execution of JS code in the TextBox control carriage return event to control the value of page elements.
(2) Implement the click event of the server control in the TextBox control carriage return event to execute the server C# code and implement related functions.
The specific implementation is as follows:
1. Register and trigger the server TextBox control input event
Event code:
protected void Page_Load(object sender, EventArgs e)
{
("onkeypress", "EnterTextBox()");
("onkeydown", "EnterTextBox()");
}
Code:
<script language="javascript">
function EnterTextBox() {
if ( == 13 && ["MessageTxt"].value != "") //Press Enter and there is a value in the text box
{
$("#<%=%>").val($("#<%=%>").val().replace(/[^\u0000-\u00FF]/g,
function ($0) {
return escape($0).replace(/(%u)(\w{4})/gi, "&#x$2;")
}));
}
}
</script>
2. Call the server Button control click event in the TextBox control in the carriage return event
Event code: Same as above.
protected void Page_Load(object sender, EventArgs e)
{
("onkeypress", "EnterTextBox()");
("onkeydown", "EnterTextBox()");
}
Code: Note that the original dom object is used to obtain the button, and it cannot be obtained using Jquery.
<script language="javascript">
function EnterTextBox() {
var button = ('<%=%>');//Get the page object corresponding to the server control
if ( == 13) //Pressed Enter
{
();
= false;
}
} </script>
In the page, the index of the textbox is 1 (or n), and the subsequent submission button is 2 (n+1). The cursor is in the textbox. After pressing, the automatic focus moves to the subsequent button, which will trigger the button click event.
However, when accessing the web page in the Lyncplus client, I encountered the situation where the TextBox control Enter autocomplete button's submission event failed (it should be that the focus should be automatically switched).
Since the TextBox control on the server does not provide events such as OnKeyPress or OnKeyDown, it is also impossible to write background code for the carriage return event to call the Button button click event.
So I searched for relevant introductions online and finally solved the following two problems:
(1) Implement the execution of JS code in the TextBox control carriage return event to control the value of page elements.
(2) Implement the click event of the server control in the TextBox control carriage return event to execute the server C# code and implement related functions.
The specific implementation is as follows:
1. Register and trigger the server TextBox control input event
Event code:
Copy the codeThe code is as follows:
protected void Page_Load(object sender, EventArgs e)
{
("onkeypress", "EnterTextBox()");
("onkeydown", "EnterTextBox()");
}
Code:
Copy the codeThe code is as follows:
<script language="javascript">
function EnterTextBox() {
if ( == 13 && ["MessageTxt"].value != "") //Press Enter and there is a value in the text box
{
$("#<%=%>").val($("#<%=%>").val().replace(/[^\u0000-\u00FF]/g,
function ($0) {
return escape($0).replace(/(%u)(\w{4})/gi, "&#x$2;")
}));
}
}
</script>
2. Call the server Button control click event in the TextBox control in the carriage return event
Event code: Same as above.
Copy the codeThe code is as follows:
protected void Page_Load(object sender, EventArgs e)
{
("onkeypress", "EnterTextBox()");
("onkeydown", "EnterTextBox()");
}
Code: Note that the original dom object is used to obtain the button, and it cannot be obtained using Jquery.
Copy the codeThe code is as follows:
<script language="javascript">
function EnterTextBox() {
var button = ('<%=%>');//Get the page object corresponding to the server control
if ( == 13) //Pressed Enter
{
();
= false;
}
} </script>