Saturday, 11 June 2016

Enable and Disable Asp.Net FileUpload Control Using jQuery

6/11/2016 - By Pranav Singh 0

This article will show you how you can enable and disable asp.net fileupload control on click of checkbox using jquery. In this when user check the checkbox fileupload control will become disable and when it uncheck it fileupload control will become enable.

So for this article first will create a new asp.net application and add the below html code.

<form id="form1" runat="server">
        <div>
            Enable Or Disable:
            <asp:CheckBox ID="CheckBox1" runat="server" />
        </div>
        <br />
        <div>
           
            File Upload Control:<asp:FileUpload ID="FileUpload1" runat="server" />
        </div>
    </form>


In above code I have added a checkbox and a file upload control.  Now add the below code into the header of the page.

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script>
        $(document).ready(function () {
            $("#<%=CheckBox1.ClientID %>").click(function () {
                var status = $("#<%=CheckBox1.ClientID %>").prop("checked");
                if (status == true) {
                    $("#<%=FileUpload1.ClientID %>").prop('disabled', true);
                } else {
                    $("#<%=FileUpload1.ClientID %>").prop('disabled', false);
                }
            });
        });
    </script>

In above code with the help of jquery I have find the status of the checkbox and then on the bases of the checkbox status enabling and disabling the asp.net file upload control. Now check the complete code of the page.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication7.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Enable and Disable Asp.Net Fileupload Control Using jQuery</title>
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script>
        $(document).ready(function () {
            $("#<%=CheckBox1.ClientID %>").click(function () {
                var status = $("#<%=CheckBox1.ClientID %>").prop("checked");
                if (status == true) {
                    $("#<%=FileUpload1.ClientID %>").prop('disabled', true);
                } else {
                    $("#<%=FileUpload1.ClientID %>").prop('disabled', false);
                }
            });
        });
    </script>
</head>
<body>
        <form id="form1" runat="server">
            <div>
                Enable Or Disable:
                <asp:CheckBox ID="CheckBox1" runat="server" />
            </div>
            <br />
            <div>
           
                File Upload Control:<asp:FileUpload ID="FileUpload1" runat="server" />
            </div>
        </form>
</body>
</html>

Now we have done run the application to check the output.

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top