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.
Some of my
previous articles are as follows: Get
Control Value By Id in Asp.Net Using JavaScript, Export
GridView Or Table Data Into jSon Format Data By C#.Net In Asp.Net Using jQuery, Add
JavaScript Function To Button Control in Asp.net Using C#, Call
C# Code or Function or Method From Javascript In Asp.Net, Get
All Checked Checkbox Value Using jQuery in Asp.Net CheckBoxList, Get
RadioButton Value Using jQuery In Asp.Net, Display
Selected Row Value Of GridView In JavaScript Alert Message Asp.Net Using C#.Net, Display
Calendar Control Selected Date Into Javascript Alert Message In Asp.Net, Confirm
Message Box With Ok and Cancel Detect On Button Click Using JavaScript In HTML
and Asp.net.
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>
|
0 comments:
Please let me know your view