March 5, 2011

Custom Validator for Checkbox server control

Custom Validator for Checkbox


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExCustomValidator.aspx.cs" Inherits="ExCusomValidator" %>

    <form id="Form1" runat="server">
            Check checkbox For Accepting the terms n conditons 
            <asp:CheckBox id="CheckBox1" runat="server" 
             Text=" Accept Terms and conditions"></asp:CheckBox>
            <asp:CustomValidator id="CustomValidator1" 
             runat="server" ErrorMessage="Please Accept Trems and Conditions" 
            <asp:Button id="Button1" onclick="Button1_Click" 
             runat="server" Text="Submit"></asp:Button>
            <asp:Label id="Label1" runat="server"></asp:Label>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ExCusomValidator : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)


    public void CustomValidator1_ServerValidate(Object source,
     ServerValidateEventArgs args)

        args.IsValid = (CheckBox1.Checked == true);

    public void Button1_Click(Object sender, EventArgs e)
        if (Page.IsValid)
            Label1.Text = "Thank you for Accepting";
            Label1.Text = "";

No comments:

Post a Comment