Technical Articles

Types of Validation Controls in ASP.Net

0 0


Example for Custom validator

In Designer aspx
  <asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
         <asp:CustomValidator ID=”CustomValidator1″ runat=”server” 
            ErrorMessage=”Not a even no” ControlToValidate=”TextBox1″ 
            ForeColor =”Red” onservervalidate=”CustomValidator1_ServerValidate”
            ></asp:CustomValidator>
        <asp:Button ID=”Button1″ runat=”server” Text=”Button” />

In aspx.cs  
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (Convert.ToInt32(args.Value) % 2 == 0)
            {
                args.IsValid = true;
            }
            else
            {
                args.IsValid = false;
            }
        }

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
× How can I help you?