Home >Web Front-end >JS Tutorial >Specific implementation of Textbox control registering carriage return event and triggering button submit event_javascript skills

Specific implementation of Textbox control registering carriage return event and triggering button submit event_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:41:091221browse
Introduction:
In the ASP.Net page, the index of the textbox is 1 (or n), and the subsequent submit button has an index of 2 (n 1). The cursor is in the textbox, and the focus is automatic after pressing Enter. Moving to the following button will trigger the button's click event.

But when accessing the web page in the Lyncplus client, I encountered a situation where the submit event of the Enter auto-complete button of the TextBox control failed (it should automatically switch focus).

Since the server-side TextBox control does not provide events such as OnKeyPress or OnKeyDown, it is impossible to write background code for the Enter event to call the Button button's click event.

So I searched for relevant introductions on the Internet, and finally solved the following two problems:
(1) Implement JS code execution in the Enter event of the TextBox control to control page elements value.
(2) Implementation of calling the click event of the server control in the Enter event of the TextBox control to execute the server C# code and implement related functions.
The specific implementation is as follows:
1. Register and trigger the enter event of the server-side TextBox control
1. PageLoad event code:
Copy code The code is 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 The code is as follows:



2. Call the server-side Button control click event in the Enter event of the TextBox control
1.PageLoad event code: Same as above.
Copy code The code is as follows:

protected void Page_Load(object sender, EventArgs e)
{
MessageTxt.Attributes.Add("onkeypress", "EnterTextBox()");
MessageTxt.Attributes.Add("onkeydown", "EnterTextBox()");
}

2.javascript code: Note that the original dom object is used to obtain the button, which cannot be obtained using Jquery.
Copy code The code is as follows:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn