asp.net aspxtextbox and other controls to achieve "carriage return analog tab" Common code collation _ practical Skills

Source: Internet
Author: User
In a recent Web project, I use devexpress third party controls.
Because this control uses the skill to use the Chinese material to be few, really is very tough, can only fumble, side develops.

Today I want to implement some edit boxes such as Aspxtextbox, aspxcombobox, etc. control carriage return to simulate tab function. This is no way, users used to return, hate to press TAB to move focus (the mouse clicks more trouble).

In the case of Aspxtextbox, many client JavaScript code can be set in the Clientsideevents property, where KeyPress is what I want to write.

First of all, have to be prepared to simulate the tab of the JS code, this online a lot, I casually d A, try useful, posted as follows:
Copy Code code as follows:

Enter key analog 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 hidden, disabled type of input box
If the next control is a button, it is also required to skip and next until a button or no control
Todo
{
i++;
if (I>=len)
Return
}
while (document.forms (0). elements (i) disabled| | Document.forms (0). elements (i) type== ' hidden '
|| Document.forms (0). elements (i) type== ' button '
|| 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 extra carriage return, otherwise enter TEXTAREA, button will send the carriage return directly!
Return
}
}
}
}

Next, insert the KeyPress event code in the Aspxeditbox control's HTML code.
Copy Code code 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>

First get the key value Event.keycode, assign to key. Then determine if the key value is equal to 13 (enter), and if so, call the preceding 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.