Click here to Skip to main content
15,902,447 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hii,

I make a web application. in this i want to add in a form like when user press the enter key it will act as tab key.

so, how this i will solve...

please help me to make out.......

Thanks and Regards...
Mitesh
Posted
Comments
Sandeep Mewara 26-Sep-12 2:16am    
Being an old member who has asked so many questions, yet fail to tag properly is bad thing.

Always tag your question correctly and mark solutions as an answer that helps.

You should subscribe to the KeyPress event of your control. Here is an example of the handler for a textbox:
C#
private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
{
   if (e.KeyChar == (char)Keys.Return)
      base.ProcessDialogKey(Keys.Tab);
}

Using this approach it is very convenient that the input focus can switch to e.g. the next textbox when the user presses enter in one textbox.
 
Share this answer
 
v2
Comments
[no name] 26-Sep-12 1:49am    
but i make Web Application.........
Kenneth Haugland 26-Sep-12 1:50am    
The you need to add appropriate tags to the question.
You can use onkeydown event to trap the event keycode and then press tab keycode.

Try something like this for the textbox:
HTML
<input type="text" onkeydown="EnterToTab()">

JS code:
JavaScript
function EnterToTab(){
  if (event.keyCode==13)
    event.keyCode=9;
  }


PS: This is not suggestible as Enter and Tab have two different functions to perform and playing with them like this not good.
 
Share this answer
 
This can be done in using JQuery in web application


XML
<!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></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>

 <script type="text/javascript">
     $(document).ready(function () {

         var inputs = $(':input').keypress(function (e) {
             if (e.which == 13) {
                 e.preventDefault();
                 var nextInput = inputs.get(inputs.index(this) + 1);
                 if (nextInput) {
                     nextInput.focus();
                 }
             }
         });

              });
 </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server" TabIndex="3"></asp:TextBox>

    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
[no name] 26-Sep-12 2:37am    
dear, it direct focus goes to submit button not to the next textbox.
Sm.Abdullah 26-Sep-12 2:53am    
nope: it must focus to next input control which needs to be focus... something going wrong at your side. Re arrange your controls. or reset tab index.it is working fine at my side.
Sm.Abdullah 26-Sep-12 6:05am    
you can try this one too.
$("input").bind("keydown", function(event) {
if (event.which == 13) {
event.stopPropagation();
event.preventDefault();
$(this).next("input").focus();
}
});
[no name] 26-Sep-12 6:17am    
i use where this event? on button onclient click...............
Sm.Abdullah 26-Sep-12 9:08am    
@Commetns
buddy i uses keydown Event which will be bind with every HTML INPUT tag with the help of JQUERY Automatically. You do not have to call explicitly with every TextBox or Controls.
Take a look here.
$("input").bind("keydown", function(event) {
alert("hello world");
}
it will bind Keydown event of every HTML INPUT Tag and shows a POP UP
so you do not have to call it for every Input field by writing KEY DOWN event one by one.
you just have to include Jquery and use document.ready function for this prupose. As i did in Answer.
i hope you understand.
Hi,

Here is the link for you

http://support.microsoft.com/kb/810203[^]

Search in Google/CP before posting a question.


Thanks
--RA
 
Share this answer
 
Comments
Sandeep Mewara 26-Sep-12 2:22am    
And how does your link answer the question? I don't find it related.
in windows we use key down event of that control
we write there

if e.keycode = keys.enter
sender.sendkeys("{TAB}")
end if
 
Share this answer
 
v2
for focusing next control
C#
private void Txt_KeyPress(object sender, KeyPressEventArgs e)
       {
           if (e.KeyChar == (char)Keys.Enter)
           {
               Control c = GetNextControl((Control)sender, true);
               if (c != null)
                   c.Focus();
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900