1、非空數(shù)據(jù)驗證控件RequiredFiledValidator。
屬性:ControlToValiata 指驗證控件對哪一個控件進行驗證。例如驗證TextBox控件的ID屬性txtPwd,只要將RequiredFiledValidator。控件的ControlToValidata屬性設(shè)置為txtPwd。代碼:this.RequiredFiledValidator1.ControlToValidata="txtPwd";
ErrorMessage屬性:用于指定頁面中使用RequiredFiledValidator控件時顯示的錯誤消息文本。代碼:this.RequeiredFiledValidator1.ErrorMessage=“*”;
2、數(shù)據(jù)比較驗證控件
CompareValidator:
重要屬性:ControlToCompare 指定要對其進行值比較的控件ID。例如驗證兩次ID。
this.compareValidator1.ControlToCompare="txtPwd";
this.compareValidator1.ControlToValidate=""txtRepwd:
Operator屬性:進行驗證時進行的操作。例如驗證輸入密碼和再次輸入密碼是否一致。
this.CompareValidator1.OPerator=ValidationCompareOperator.Equal;
Type屬性:指定要進行比較的兩個值的數(shù)據(jù)類型;例如驗證兩者的數(shù)據(jù)類型
this.。。Type=ValidationDataType.String;
ValueToCompare屬性:指定要比較的值。
<title>數(shù)據(jù)驗證技術(shù)</title></head><body> <form id="form1" runat="server"> <div> <h2>數(shù)據(jù)驗證技術(shù)</h2> <h3>非空數(shù)據(jù)驗證</h3> <div > <asp:Label ID="lab" Text="用戶信息" runat ="server" ></asp:Label ><br /><br /> <asp:Label ID="Name" Text ="姓名:" runat ="server" ></asp:Label> <asp:TextBox ID="txtName" runat="server" ></asp:TextBox> <asp:RequiredFieldValidator ID="RedFile" runat ="server" ControlToValidate ="txtName" SetFocusOnError ="true" ErrorMessage ="姓名不能為空" ></asp:RequiredFieldValidator><br /><br /><br /> <asp:Button ID="btOK" runat="server" Text="驗證" OnClick="btOK_Click" style="height: 21px" /> </div> </div> <div> <hr /> <h3>數(shù)據(jù)比較控件驗證</h3> <var> <asp:Label ID="LabTxt" runat="server" Text="用戶信息" BorderStyle ="NotSet"></asp:Label><br /> </var> <asp:Label ID="lab2" runat="server" Text="姓名:"></asp:Label> <asp:TextBox ID="lab3" runat ="server" ></asp:TextBox> <asp:RequiredFieldValidator ID="RequFlie2" runat="server" ErrorMessage ="姓名不能為空" SetFocusOnError ="true" ControlToValidate ="txtName"></asp:RequiredFieldValidator><br /><br /> <asp:Label ID ="lab4" runat="server" Text ="密碼:" ></asp:Label> <asp:TextBox ID="txtPwd" runat ="server" TextMode="Password" ></asp:TextBox><br /><br /> <asp:Label ID ="lab5" runat="server" Text ="確認密碼:"></asp:Label> <asp:TextBox ID="txtRepwd" runat ="server" TextMode ="Password" ></asp:TextBox> <asp:CompareValidator ID="Comval" runat ="server" ControlToValidate ="txtRepwd" ControlToCompare ="txtPwd" ErrorMessage="確認密碼與原密碼不匹配"></asp:CompareValidator><br /><br /> <asp:Button ID="btnCheck" runat ="server" Text ="驗證2" OnClick="btnCheck_Click" /> </div> </form>
新聞熱點
疑難解答
圖片精選