connectseekers.com

Sunday, 12 June 2016

Enable and Disable Asp.Net FileUpload Control Using JavaScript

6/12/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 JavaScript. 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>
        function EnableDisableControl() {
            var status = document.getElementById("<%=CheckBox1.ClientID %>").checked;
            if (status == true) {
                document.getElementById("<%=FileUpload1.ClientID %>").disabled = 'disabled';
             } else {
                 document.getElementById("<%=FileUpload1.ClientID %>").disabled = '';
             }
         }

    </script>

In above code with the help of JavaScript 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.

After this just need the assign the JavaScript function on click on the checkbox. Have a look of the below code.

        <div>
            Enable Or Disable:
                <asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:EnableDisableControl();" />
        </div>

Now check the complete code of the page.

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Enable and Disable Asp.Net FileUpload Control Using JavaScript</title>
    <script>
        function EnableDisableControl() {
            var status = document.getElementById("<%=CheckBox1.ClientID %>").checked;
            if (status == true) {
                document.getElementById("<%=FileUpload1.ClientID %>").disabled = 'disabled';
             } else {
                 document.getElementById("<%=FileUpload1.ClientID %>").disabled = '';
             }
         }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Enable Or Disable:
                <asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript:EnableDisableControl();" />
        </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.



DOWNLOAD

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
Email Id : contact@aspdotnet-pools.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


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top