Hello,
any one can help me " i want that When i press ENTER key control focus on next tab in asp.net

Recommended Answers

All 5 Replies

Rather than asp.net, you should handle this client side using javascript or easier with jQuery. Here is an example ...

 $(document).keypress(function(e) {
     if(e.which == 13) {
         alert('You pressed enter!');
     }
 });

Instead of the alert box, use the jQuery focus method to give the target element focus, or show/hide divs, etc...

Hello JorgeM,

I use this code but it nor work

<script language ="javascript" type ="text/javascript">

    $(document).keypress(function (e) {
        alert('hello');
        if (e.which == 13) {
            alert('You pressed enter!');
        }
            });


</script>

<body>
<form id="form1" runat="server">
<div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>

</body>

So, if you are not familiar with jQuery, you may want to do some reading up on it. Its a very powerful JavaScript library. Very easy to use.

In your example, you may have forgotten to reference the jQuery library. Here is a complete example which you can adapt to your needs.

<%@ Page Language="VB" %>

<!DOCTYPE html>
<html>
<head runat="server">
    <title>Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
    <asp:Button ID="Button1" runat="server" Text="Button" />
</form>

<script>
    $(document).keypress(function (e) {
        if (e.which == 13) {
            alert('You pressed enter!');
        } else {
            alert('You did not press enter!');
        }
    });
</script>
</body>
</html>

Hello JorgeM,

Thnaks for your time but this code still not working

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

<!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="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type ="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>

</body>
<script type ="text/javascript">
    $(document).keypress(function (e) {
        if (e.which == 13) {
            e.keyCode = 9;
        } else {
            alert('You did not press enter!');
        }
    });
</script>

The first issue is that you have the script block outside of the closing body tag. Secondly to switch the "enter" key for "tab", you'll need to do some additional reasearch. I havent had time to test this myself, but did a quick search and found a solution online which indicates working, tested code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.