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.