Implementation of controls such as asp.net ASPxTextBox & quot; press enter to simulate common code of Tab & quot;

Source: Internet
Author: User

Recently I am working on a Web project. I use a third-party control of DevExpress.
Because the control has few skills in Chinese, it is really awkward. It can only be explored and developed.

Today, I want to implement some editing boxes such as ASPxTextBox, ASPxComboBox, and other controls to press enter to simulate the Tab function. This is no way. You are used to press the carriage return and hate to press the Tab to move the focus (it is more troublesome to click the mouse ).

Taking ASPxTextBox as an example, many client JavaScript code can be set in the ClientSideEvents attribute, where KeyPress is what I want to write.

First, you have to prepare the JS Code to simulate the Tab. There are a lot of code on the Internet. I 'd like to try it and paste it as follows:
Copy codeThe Code is as follows:
// Press the Enter key to simulate the tab in onkeydown.
Function EnterAsTab ()
{
Var el_keydown = window. event. srcElement;
Var len;
If (window. event. keyCode = 13 & el_keydown.type! = "Textarea ")
| (Window. event. keyCode = 13 & window. event. ctrlKey & el_keydown.type = "textarea "))
{
Len = document. forms (0). length;
For (var I = 0; I <len; I ++)
{
If (document. forms (0). elements (I) = el_keydown)
{
// Skip the hidden and disabled input boxes
// If the next control is a button, skip the next control until it is not a button or has no control.
Do
{
I ++;
If (I> = len)
Return;
}
While (document. forms (0). elements (I). disabled | document. forms (0). elements (I). type = 'den den'
| Document. forms (0). elements (I). type = 'click'
| Document. forms (0). elements (I). type = 'submit'
| Document. forms (0). elements (I). type = 'reset'
| Document. forms (0). elements (I). type = 'href '));
// Alert ('object '+ I +' type: '+ document. forms (0). elements (I). type );
Document. forms (0). elements (I). focus ();
Document. forms (0). elements (I). select ();
Event. returnValue = false; // discard the excessive carriage return. Otherwise, the enter textarea and button will directly send the carriage return!
Return;
}
}
}
}

Then, the KeyPress Event code is inserted into the HTML code of the ASPxEditBox control.
Copy codeThe Code is as follows:
<Dxe: ASPxTextBox ID = "txtCodeName" runat = "server" Width = "170px"
Text = '<% # Bind ("CodeName") %>'>
<ClientSideEvents KeyPress = "function (s, e) {var key = event. keyCode;
If (key = 13) {EnterAsTab () ;}} "/>
</Dxe: ASPxTextBox>

Obtain the key value event. keyCode and assign it to the key. Then judge whether the key value is equal to 13 (enter key). If yes, call the previous JS function EnterAsTab ().
Other controls are similar.

Related Article

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.