Custom Validator Control In ASP.NET Web forms | Form Validation | ASP.NET WebForms
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ANOTHER_EXAMPLE_CV_PRACTICE.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1{
width:100%;
}
.auto-style2 {
width: 185px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="4" cellspacing="4" class="auto-style1">
<tr>
<td class="auto-style2">ENTER EVEN NUMBER</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="195px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic" ForeColor="Red" ErrorMessage="Please Enter a number" ControlToValidate="TextBox1" SetFocusOnError="true"></asp:RequiredFieldValidator>
<%--Custom Validator is used when we want to apply our own logic--%>
<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ForeColor="Red" ErrorMessage="Please enter even number" ControlToValidate="TextBox1" SetFocusOnError="true" OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="Button1" runat="server" Text="SUBMIT"/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
.png)
.png)
.png)
.png)
.png)
.png)
.png)
Comments
Post a Comment