Monday, 25 June 2012

requirefieldvalidator onclientside validator with with confirmation checkbox

 <script type="text/javascript">
        function che() {
            var ch = document.getElementById('<%=CheckBox1.ClientID %>');
            if (Page_ClientValidate()) {
                if (!ch.checked) {
                    alert("Please select checkbox first.");
                    return false;
                }
            }
        }   
    </script>

HTML-------------------------------------

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       <asp:RequiredFieldValidator id="rq1" ControlToValidate="TextBox1" ErrorMessage="Name cannot be blank" Display="Dynamic" runat="server"/>
        <asp:CheckBox ID="CheckBox1" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="Button"
            OnClientClick="return che();" onclick="Button1_Click" ValidationGroup="2" />

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...