Thursday, September 17, 2009

How to validate checkbox inside CreateUserwizard Control/Wizard control ?

Validate checkbox inside Wizard step
We need a custom validator and a small client side javascript
<asp:WizardStep runat="server"
AllowReturn="False">


<asp:CheckBox ID="chkterm"
runat="server"
/>I agree with the Terms and Conditions


<asp:CustomValidator ID="CustomValidatorAgree"
runat="server"
ClientValidationFunction='validatechkbox'

ControlToValidate="txtinterest" ErrorMessage="Please read and agree Terms and Conditions" ValidateEmptyText="True"></asp:CustomValidator>

</asp:WizardStep>
< script language="javascript" type="text/javascript"> function validatechkbox(obj, args) {

var controlID1 = '<%= chkterm.ClientID %>';var checkbox = document.getElementById(controlID1); args.IsValid = checkbox.checked;} </script>

Note :Set the ControlToValidate validate property of custom validator to any other controles in the formValidate checkbox inside CreateUserWizard<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">            <WizardSteps>                <asp:CreateUserWizardStep runat="server">                    <ContentTemplate>


<asp:CheckBox ID="chkterm" runat="server" /><asp:TextBox runat="server" ID="txtvalidate" Text="I agree with the Terms and Conditions" ReadOnly ="true" Width="250px" ></asp:TextBox><asp:CustomValidator ID="CustomValidatorAgree" runat="server" ClientValidationFunction='validatechkbox'
ControlToValidate="txtvalidate" ErrorMessage="Please read and agree Terms and Conditions" ValidateEmptyText="True" Display="Dynamic" ValidationGroup="CreateUserWizard1" ></asp:CustomValidator>
<script language="javascript" type="text/javascript">


        function validatechkbox(obj, args) {            var controlID1 = 'CreateUserWizard1_CreateUserStepContainer_chkterm';
            var checkbox = document.getElementById(controlID1);           args.IsValid = checkbox.checked;
}</script>

No comments:

Post a Comment