`
yangle926
  • 浏览: 58314 次
  • 性别: Icon_minigender_1
  • 来自: 洛阳
社区版块
存档分类
最新评论

asp.net中的验证控件的使用

    博客分类:
  • .NET
阅读更多
    前台:
<h4>验证控件使用测试</h4>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ValidationGroup="vGroup1" ErrorMessage="不能为空!" Text="*" Display="Static"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
            ControlToValidate="TextBox1" ErrorMessage="格式不正确!" Display="None"
            ValidationGroup="vGroup1" ValidationExpression="^\d-\d{3}-\d{3}-\d{4}$"></asp:RegularExpressionValidator>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="vGroup1" />
        <asp:Button ID="Button1" runat="server" Text="Button"  ValidationGroup="vGroup1" OnClick="Button1_Click" />

    后台:
protected void Button1_Click(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('验证测试通过!');</script>");
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics