Tuesday, October 6, 2015

Validate Listbox Ckeckbox Abd Radio Buttons

<asp:ListBox ID="ListBox1" runat="server" Rows="6" SelectionMode="Multiple">
            <asp:listitem text="India" value="1"></asp:listitem>
            <asp:listitem text="US" value="2"></asp:listitem>
            <asp:listitem text="UK" value="3"></asp:listitem>
            <asp:listitem text="China" value="4"></asp:listitem>
            <asp:listitem text="Russia" value="5"></asp:listitem>
            <asp:listitem text="New Zealand" value="6"></asp:listitem>
        </asp:ListBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required two country" ClientValidationFunction="Validate_ListBox"></asp:CustomValidator>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" /><asp:ListBox ID="ListBox1" runat="server" Rows="6" SelectionMode="Multiple">
            <asp:listitem text="India" value="1"></asp:listitem>
            <asp:listitem text="US" value="2"></asp:listitem>
            <asp:listitem text="UK" value="3"></asp:listitem>
            <asp:listitem text="China" value="4"></asp:listitem>
            <asp:listitem text="Russia" value="5"></asp:listitem>
            <asp:listitem text="New Zealand" value="6"></asp:listitem>
        </asp:ListBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required two country" ClientValidationFunction="Validate_ListBox"></asp:CustomValidator>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
        <script>
            function Validate_ListBox(sender, args) {
                var Listoptions = document.getElementById("<%=ListBox1.ClientID%>").options;
                var Selectedcount = 0;
                for (var i = 0; i < Listoptions.length; i++) {
                    if (Listoptions[i].selected == true) {
                        Selectedcount++;
                    }
                }
                if (Selectedcount <= 2) {
                    args.IsValid = false;
                } else {
                    args.IsValid = true;
                }
            }
        </script>


        /////////////////////////////////////////////
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            function CheckBoxList1_Validation(sender, args) {
                args.IsValid = false;
                var cnt = $("#CheckBoxList1 input:checked").length;
                args.IsValid = (cnt >= 2);
            }
        </script>
        Select at least 2 countries:
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:listitem text="India" value="1"></asp:listitem>
            <asp:listitem text="US" value="2"></asp:listitem>
            <asp:listitem text="UK" value="3"></asp:listitem>
            <asp:listitem text="China" value="4"></asp:listitem>
            <asp:listitem text="Russia" value="5"></asp:listitem>
            <asp:listitem text="New Zealand" value="6"></asp:listitem>
        </asp:CheckBoxList>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select at least 2 countries" ClientValidationFunction="CheckBoxList1_Validation" ForeColor="Red"></asp:CustomValidator>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />


        ///////////////////////////////////////////////////////
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            function RadioButtonList1_Validate(sender, args) {
                args.IsValid = ($("#RadioButtonList1 :radio:checked").length > 0);
            }
        </script>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
           <asp:listitem text="India" value="1"></asp:listitem>
            <asp:listitem text="US" value="2"></asp:listitem>
            <asp:listitem text="UK" value="3"></asp:listitem>
            <asp:listitem text="China" value="4"></asp:listitem>
            <asp:listitem text="Russia" value="5"></asp:listitem>
            <asp:listitem text="New Zealand" value="6"></asp:listitem>
        </asp:RadioButtonList>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select a country" Display="Dynamic" ClientValidationFunction="RadioButtonList1_Validate" ForeColor="Red"></asp:CustomValidator>
        <br />

        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />

Enable And Disable

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            $(document).ready(function () {
                //Listen for a key up event on the search input
                $('#txt_search').keyup(function () {
                    //When a user presses and releases a key
                    //Check to see if the length of the inputted
                    //data is greater than 2
                    if ($(this).val().length > 2) {
                        //If the input length is greater than
                        //two then we enable the search button
                        $('#btn_search').prop("disabled", false);
                    } else {
                        //If the input length is equal to 2 or less we disable the search button
                        $('#btn_search').prop("disabled", true);
                    }
                });
            });
        </script>
      
        <asp:TextBox ID="txt_search" runat="server"></asp:TextBox>
        <asp:Button ID="btn_search" runat="server" Text="Search" disabled />
        <asp:TextBox ID="txt_search" runat="server"></asp:TextBox>

        <asp:Button ID="btn_search" runat="server" Text="Search" disabled />

jquery datepicker calendar

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
        <script>
        $(document).ready(function () {
            $("#txt_date").datepicker();
        });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <h3>Click to select a date :</h3>
                <asp:textbox ID="txt_date" runat="server"></asp:textbox>
            </div>
        </form>
    </body>

    </html>