Asp.net 回车默认按钮

时间:2024-08-17 21:37:32

<head>

<script type="text/javascript">

function OnKey()
      {
          if (event.keyCode == 13)
          {
              document.getElementById('<%=btnLogin.ClientID%>').focus();
              document.getElementById('<%=btnLogin.ClientID%>').click();
          }
      }

document.onkeydown = OnKey;
</script>

</head>

我目前认为一般的块标签 好像都有 DefaultButton  这个默认的熟悉

<body>    

<form id="form1" runat="server" DefaultButton="btnLogin">

<asp:Panel ID="Panel2" runat="server" DefaultButton="btnLogin">
                        <table  border="0px" cellpadding="0px" cellspacing="0px" style="border: 0px;">
                            <tr>
                                <td>
                                    User Name<b>:</b>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:TextBox ID="txtName" runat="server" CssClass="txtbox" BorderStyle="Inset"></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style="height: 30px;">
                                    Pin<b>:</b>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:TextBox ID="txtPwd" runat="server" CssClass="txtbox" BorderStyle="Inset" TextMode="Password"></asp:TextBox><br>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <br>
                                    <asp:Button ID="btnLogin" CssClass="btn" runat="server" Text="Login" OnClick="btnLogin_Click"
                                        UseSubmitBehavior="False" />
                                    &nbsp;&nbsp;
                                    <asp:Button ID="btnLogout" CssClass="btn" runat="server" Text="Logout" OnClick="btnLogout_Click"
                                        UseSubmitBehavior="False" />
                                </td>
                            </tr>
                        </table>

</body>