Sunday, 3 November 2013

How to validate checkbox before save data

<script type="text/javascript" language="javascript">


   // This function is used for validatecheckbox

    function ValidateCheckBox() {
        var chekbox = document.getElementById('<%=chkterms.ClientID %>');
        var spanelement = document.getElementById('Span1')
        if (chekbox.checked == true) {
            spanelement.style.display = 'none';
        } else {
            spanelement.style.display = '';
            return false;
        }
    }    
</script>


  <tr>
  <td align="left" colspan="2">
            <asp:CheckBox ID="chkterms" runat="server" onchange="javascript:ValidateCheckBox();" />
            <strong style="font: bold 16px 'Century Gothic'"><a href="../Terms.aspx" target="_blank">
                <u>I Agree Terms and Conditions</u></a></strong>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <span id="Span1" style="color: red; display: none;">You must and should Agree the Terms
                and Conditions </span>
        </td>
    </tr>


   <tr>
        <td>
            <ul class="pager wizard">
                <li class="back">
                    <asp:LinkButton ID="Btn2" runat="server" OnClick="Btn2_Click">Previous</asp:LinkButton>
                </li>
            </ul>
        </td>
        <td>
            <ul class="pager wizard">
                <li class="back">
                    <asp:LinkButton ID="btnsave" runat="server" ValidationGroup="regroup" OnClientClick="javascript:return ValidateCheckBox();"
                        OnClick="btnsave_Click">Save</asp:LinkButton>
                </li>
            </ul>
        </td>
    </tr>

  protected void btnsave_Click(object sender, EventArgs e)
    {
 Response.Redirect("AccountPreview.aspx",false);
}


No comments:

Post a Comment