asp. net data validation control
- 2021-07-09 07:48:44
- OfStack
1. Non-null data validation control RequiredFiledValidator.
Property: ControlToValiata refers to which 1 control the validation control validates. For example, validate the ID property txtPwd of an TextBox control by setting RequiredFiledValidator. The ControlToValidata property of the control is set to txtPwd. Code: this.RequiredFiledValidator1.ControlToValidata= "txtPwd";
ErrorMessage property: Used to specify the error message text displayed when the RequiredFiledValidator control is used in the page. Code: this.RequeiredFiledValidator1.ErrorMessage= "*";
2. Data comparison validation control
CompareValidator:
Important property: ControlToCompare specifies the control ID for which to compare values. For example, verify ID twice.
this.compareValidator1.ControlToCompare="txtPwd";
this.compareValidator1.ControlToValidate=""txtRepwd:
Operator property: The action taken when validating. For example, verify whether the input password and re-enter the password are 1.
this.CompareValidator1.OPerator=ValidationCompareOperator.Equal;
Type attribute: Specifies the data type of the two values to be compared; For example, validating the data types of both
this.. . Type = ValidationDataType. String;
ValueToCompare Attribute: Specifies the value to compare.
<title> Data verification technology </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2> Data verification technology </h2>
<h3> Non-null data validation </h3>
<div >
<asp:Label ID="lab" Text=" User information " runat ="server" ></asp:Label ><br /><br />
<asp:Label ID="Name" Text =" Name :" runat ="server" ></asp:Label>
<asp:TextBox ID="txtName" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RedFile" runat ="server" ControlToValidate ="txtName" SetFocusOnError ="true" ErrorMessage =" Name cannot be empty " ></asp:RequiredFieldValidator><br /><br /><br />
<asp:Button ID="btOK" runat="server" Text=" Validation " OnClick="btOK_Click" style="height: 21px" />
</div>
</div>
<div>
<hr />
<h3> Data comparison control validation </h3>
<var>
<asp:Label ID="LabTxt" runat="server" Text=" User information " BorderStyle ="NotSet"></asp:Label><br />
</var>
<asp:Label ID="lab2" runat="server" Text=" Name: "></asp:Label>
<asp:TextBox ID="lab3" runat ="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequFlie2" runat="server" ErrorMessage =" Name cannot be empty " SetFocusOnError ="true" ControlToValidate ="txtName"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID ="lab4" runat="server" Text =" Password: " ></asp:Label>
<asp:TextBox ID="txtPwd" runat ="server" TextMode="Password" ></asp:TextBox><br /><br />
<asp:Label ID ="lab5" runat="server" Text =" Confirmation password: "></asp:Label>
<asp:TextBox ID="txtRepwd" runat ="server" TextMode ="Password" ></asp:TextBox>
<asp:CompareValidator ID="Comval" runat ="server" ControlToValidate ="txtRepwd" ControlToCompare ="txtPwd" ErrorMessage=" Confirm that the password does not match the original password "></asp:CompareValidator><br /><br />
<asp:Button ID="btnCheck" runat ="server" Text =" Validation 2" OnClick="btnCheck_Click" />
</div>
</form>
3. Data type validation control
CompareValidator validates the user's input against a specific data type to ensure whether the user is entering a number, a date, and so on.
Example: Control properties used, CotrolToValidator, operator, type properties. Verify that the date of birth entered by the user matches the type.
Demonstration of fade-in and fade-out effect of JQuery. .
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>jquery Dynamic </title>
<script src="">
</script>
<script type="text/javascript" >
$(function(){
$(".nav li").hover(function(){
$("ul",this ).fadeIn();
},
function(){
$("ul")
})
$)
</script>
<meta charset="utf-8" />
<style type="text/css" >
body{
font-family :Arial ,sans-serif;
font-size:15px;
}
.nav{
margin:0;
padding:0;
list-style:none ;
}
.nav li {
float :left ;
width:150px;
position :relative ;
}
.nav li a{
background:#262626;
color:#fff;
display :block ;
padding :8px 7px 8px 7px;
text-decoration:none ;
text-align :center ;
text-transform :uppercase ;// Lowercase to uppercase
}
.nav li a:hover {
color:#bf3826;
}
.nav ul{
position :absolute ;
left:0px;
display:none ;
margin: 0 0 0 -1px;
padding :0;
list-style:none ;
border-bottom :3px solid #bf3826;
}
.nav ul li{
width:180px;
float :left ;
border-top :none ;
}
.nav ul a{
display :block ;
height :15px;
padding: 8px 7px 8px 7px;
color :#fff;
text-decoration :none ;
border-top:none ;
border-bottom:1px dashed #bf3826;
}
</style>
</head>
<body>
<div style="width :650px ; margin:0 auto">
<ul class=" nav">
<li><a href=" #">Home</a></li>
<li>
<a href="#">ipnoe</a>
</li>
</ul
</div>
</body>
</html>