我是菜鸟,问的问题如果太可笑,请大家原谅,毕竟刚学才3天。A.aspx是让用户输入用户名和密码的,问题:“确定”后,如果 用户名和密码 不正确(未通过验证)时,返回到A.aspx页面,
       可是每次都要用鼠标点到 用户名 输入框,
       有什么方法可以在返回时直接 聚焦 到 “用户名” 输入框上呢?具体该怎么做,请大虾们指点。另外,哪位有 只允许输数字 的程序段,如:身份证号只能允许输入数字。多谢了!

解决方案 »

  1.   

    自带的有一个验证控件可以
    [C#] 
    <%@ Page Language="C#" AutoEventWireup="True" %> <html>
     <head>    <script runat="server">
     
           void ValidateBtn_Click(Object sender, EventArgs e) 
           {
              if (Page.IsValid) 
              {
                 lblOutput.Text = "Page is Valid!";
              }
              else 
              {
                 lblOutput.Text = "Page is InValid! :-(";
              }
           }
     
        </script>
     
     </head>
     <body>
     
        <h3>RegularExpressionValidator Example</h3>
        <p>
     
        <form runat="server">
     
           <table bgcolor="#eeeeee" cellpadding="10">
              <tr valign="top">
                 <td colspan="3">
                    <asp:Label ID="lblOutput" 
                         Text="Enter a 5 digit zip code" 
                         runat="server"/>
                 </td>
              </tr>
     
              <tr>
                 <td colspan="3">
                    <b>Personal Information</b>
                 </td>
              </tr>
              <tr>
                 <td align="right">
                    Zip Code:
                 </td>
                 <td>
                    <asp:TextBox id="TextBox1" 
                         runat="server"/>
                 </td>
                 <td>
                    <asp:RegularExpressionValidator id="RegularExpressionValidator1" 
                         ControlToValidate="TextBox1"
                         ValidationExpression="\d{5}"
                         Display="Static"
                         ErrorMessage="Zip code must be 5 numeric digits"
                         EnableClientScript="False" 
                         runat="server"/>
                 </td>
              </tr>
              <tr>
                 <td></td>
                 <td>
                    <asp:Button text="Validate" 
                         OnClick="ValidateBtn_Click" 
                         runat=server />
                 </td>
                 <td></td>
              </tr>
           </table>
     
        </form>
     
     </body>
     </html>
      

  2.   

    第一个问题:
    <body ... onload="javascript:Form1.FName.focus()">
    基中FName是你窗体上需获取输入焦点的TextBox的ID
    第二个问题:
    使用正则表达式:
    if(!Regex.IsMatch(FIDCardID.Text,@"^(\d{14}[\dxX])$|^(\d{17}[\dxX])$"))
    {
    errorFieldNames +="身份证号;";
    errorMessages +="格式不对!,必须是以数字或英文字母!;";
    errorCount++;
    }
    其中FIDCardID是你的窗体上输入身份证号的TextBox的ID