Fill Asp.Net DropDownList With Json Data (JQuery)

Here we will see how to fill asp.net dropdownlist control with json data.

Code is as follows: Continue reading Fill Asp.Net DropDownList With Json Data (JQuery)

Advertisements

Prevent Cut, Copy And Paste Operation For Text Box In Asp.Net Using Jquery.

Here we will see how to block a user from performing CUT, COPY and PASTE operation on a particular textbox using jQuery. Sometimes it is required to disable the cut copy paste operation and make user mandatory to type the details.

The code is as follows: Continue reading Prevent Cut, Copy And Paste Operation For Text Box In Asp.Net Using Jquery.

Check-Box List Validation In Asp.net

Here we will see how to validate check box list control in asp.net. We will use javascript and custom validation to implement this functionality.
The code is as follows:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function CheckboxValidation(sender, args) {
            var checkBoxList = document.getElementById("<%=chk_list1.ClientID %>");
            var checkboxes = checkBoxList.getElementsByTagName("input");
            var isValid = false;
            for (var i = 0; i < checkboxes.length; i++) {
                if (checkboxes[i].checked) {
                    isValid = true;
                    break;
                }
            }
            args.IsValid = isValid;
        }       
    </script>
</head>
<body>
    <form id="form1" runat="server">        
        <div>
            <asp:CheckBoxList runat="server" ID="chk_list1">
                <asp:ListItem Text="Example 1" Value="Example 1"></asp:ListItem>
                <asp:ListItem Text="Example 2" Value="Example 2"></asp:ListItem>
                <asp:ListItem Text="Example 3" Value="Example 3"></asp:ListItem>
                <asp:ListItem Text="Example 4" Value="Example 4"></asp:ListItem>
                <asp:ListItem Text="Example 5" Value="Example 5"></asp:ListItem>
                <asp:ListItem Text="Example 6" Value="Example 6"></asp:ListItem>
            </asp:CheckBoxList>
            <asp:CustomValidator ID="Checkbox_CustomValidator" runat="server"
                ValidationGroup="CheckBoxValidation"                
                Display="None"
                ClientValidationFunction="CheckboxValidation"                                
                ErrorMessage="One or more checkboxes must be chosen">
            </asp:CustomValidator>
            <asp:Button runat="server" ID="btn_submit" Text="Validate" ValidationGroup="CheckBoxValidation" />
            <asp:ValidationSummary runat="server" ID="validateionsummary" ValidationGroup="CheckBoxValidation" ShowMessageBox="true" ShowSummary="false" />
        </div>
    </form>
</body>
</html>

Check Un-check All CheckBox Inside A Repeater

Here we will see how to check uncheck all items in repeater using jQuery. Here we have an additional checkbox (Select All) which will be used to check all the checkboxes that are present in the repeater control.

The code is as follows: Continue reading Check Un-check All CheckBox Inside A Repeater

Display Line Break In Javascript Alert Message Box.

Here we will see how to add a new line break (<br/>) to javaScript alert message box.

To implement this functionality you have to use new line character (\r\n).

Code is as follows: Continue reading Display Line Break In Javascript Alert Message Box.

JQuery UI Autocomplete Textbox Using AJAX Page/Web Method Asp.net

Here we will see how to implement auto complete textbox functionality using jquery ajax call to web method. There are times when we need to show data to user without a post back. We can call the code behind method(Server side method) with jquery ajax.

The code is as follows: Continue reading JQuery UI Autocomplete Textbox Using AJAX Page/Web Method Asp.net

Page.IsValid And Page.Validate in Asp.net

Here we will see the use of Page.IsValid and Page.Validate in Asp.net.

Suppose we have a login form with two text box(username and password) and a submit button and we have to validate the user input before submitting to server so that only valid data goes to server.

We can achieve this by applying client side validations but always remember that the client side validations are not secure as a hacker can disable the javascript and bypass our validations. Here is where the Page.Validate() method and Page.IsValid property comes into play.

The Page.Validate() method is fired automatically by controls that have the CausesValidation property set to true. Note that the Button control’s CausesValidation property is true by default.

The code is as follows: Continue reading Page.IsValid And Page.Validate in Asp.net