In asp.net, press enter to replace the Tab key.

Source: Internet
Author: User

When a large amount of content is added to a webpage, You need to press enter to replace the Tab key and enter the content in order.
In asp.net, The fouce function has functions, which are both control focus. However, to replace the Tab key with carriage return, you must use a scripting language.
In fact, the principle is very simple. In the page event, the detection window. event. keyCode is 13 (both the key value of the carriage return), with 9 (both the key value of the Tab key ).

<Script language = "JavaScript" type = "text/javascript">
<! --
Specified parameter Doc ument. attachEvent ("onkeydown", function (){
If (window. event. keyCode = 13 ){
Window. event. keyCode = 9;
}
});
// -->
</Script>

Of course, to make the controls on the asp.net page "Tab" in a certain order, you must set the TabIndex values of these controls in the order you need.

<Asp: TextBox ID = "TextBox1" runat = "server" AutoCompleteType = "Department" TabIndex = "1"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox2" runat = "server" TabIndex = "2"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox3" runat = "server" TabIndex = "3"> </asp: TextBox>
<Br/>
<Asp: TextBox ID = "TextBox4" runat = "server" TabIndex = "4"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox5" runat = "server" TabIndex = "5"> </asp: TextBox> <br/>
<Asp: Button ID = "Button1" runat = "server" Text = "Button"/> </div>

In this example, only press enter to replace the Tab key, but when you really need to press enter, you can only click the button with the mouse. I want to implement a more ideal solution. When all the text boxes have been filled in, and the focus (Tab) arrives at the submit button, press enter to submit them directly, if anyone can implement this idea, please leave a message here. I am very grateful!
The Code is as follows:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default3.aspx. cs" Inherits = "Default3" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<Script language = "JavaScript" type = "text/javascript">
<! --
Specified parameter Doc ument. attachEvent ("onkeydown", function (){
If (window. event. keyCode = 13 ){
Window. event. keyCode = 9;
}
});
// -->
</Script>

</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: TextBox ID = "TextBox1" runat = "server" AutoCompleteType = "Department" TabIndex = "1"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox2" runat = "server" TabIndex = "2"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox3" runat = "server" TabIndex = "3"> </asp: TextBox>
<Br/>
<Asp: TextBox ID = "TextBox4" runat = "server" TabIndex = "4"> </asp: TextBox> <br/>
<Asp: TextBox ID = "TextBox5" runat = "server" TabIndex = "5"> </asp: TextBox> <br/>
<Asp: Button ID = "Button1" runat = "server" Text = "Button"/> </div>
</Form>
</Body>
</Html

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.