Example jQuery Validate on CheckBoxList using C#

Example of jQuery Validate on CheckBoxList in Asp.Net using C#


In this post we consider a Example of checkboxlist and validate the checkboxlist using JQuery. As we know that google provide many Jquery for performing many examples in asp.net so if you want to download then you do otherwise you can use these jqury by giving link in your application. In this asp.net tutorial Example blog we explain many post related to the checkboxlist control these are :

Other Checkbox related post aur example:




Function of  jQuery Validate:

Here we take give jquery function of performing the validation on checkboxlist in asp.net page.
<script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $('#btnSubmit').click(function () {
                if ($('#chktech input:checked').length > 0) {
                    return true;
                }
                else {
                    alert('Please select atleast one technology')
                    return false;
                }
            })
        });

Function of jQuery for select one checkbox from checkboxlist:

This function is use to selecting checkbox for given checkboxlist.

$(function () {
            $("[id*=chkAll]").bind("click", function () {
                if ($(this).is(":checked")) {
                    $("[id*=chk] input").attr("checked", "checked");
                } else {
                    $("[id*=chk] input").removeAttr("checked");
                }
            });
            $("[id*=chkFruits] input").bind("click", function () {
                if ($("[id*=chk] input:checked").length == $("[id*=chk] input").length) {
                    $("[id*=chkAll]").attr("checked", "checked");
                } else {
                    $("[id*=chkAll]").removeAttr("checked");
                }
            });
        });


jQuery Validate Example in asp.net

                              Example jQuery Validate on CheckBoxList
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="vcheckbox.aspx.cs" Inherits="vcheckbox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>jQuery Validate on CheckBoxList in Asp.Net using C#</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $('#btnSubmit').click(function () {
                if ($('#chktech input:checked').length > 0) {
                    return true;
                }
                else {
                    alert('Please select atleast one technology')
                    return false;
                }
            })
        });

    </script>
</head>
<body>
    <form id="form" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    <b>Select Option :</b>
                </td>
                <td>
                    <asp:CheckBoxList ID="chktech" runat="server">
                        <asp:ListItem Value="1" Text="Option1" />
                        <asp:ListItem Value="2" Text="Option2" />
                        <asp:ListItem Value="3" Text="Option3" />
                        <asp:ListItem Value="4" Text="Option4" />
                        <asp:ListItem Value="5" Text="Option4" />
                    </asp:CheckBoxList>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:Button ID="btnSubmit" Text="Submit" runat="server" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
Example jQuery Validate on CheckBoxList

Exampling asp.net jquery Example:

In this example we take a checkboxlist the some items and consider one asp.net button control also. Now , the on client check event use jquery function.


Other asp.net related Examples:


Comments

Popular posts from this blog