Saturday 5 October 2013

How to clear FileUpload Control data using JavaScript in ASP.NET


In this article I will explain How to clear FileUpload Control data using JavaScript in ASP.NET

To clear file upload control in JavaScript we need to write the following code your page

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title>validate fileupload control using Jquery in ASP.NET</title>
<script language="javascript" type="text/javascript">
function ClearFileUploadControl() {
var uplctrl = document.getElementById("fileupload1");
uplctrl.select();
clrctrl = uplctrl.createTextRange();
clrctrl.execCommand('delete');
uplctrl.focus();
}
</script>
</head>



<body>
<form id="form1" runat="server">
<div>
<table><tr>
<td><b>Upload Images:</b></td>
<td><asp:FileUpload ID="fileupload1" runat="server" /></td>
</tr>
<tr><td></td><td><asp:Button ID="btnSubmit" Text="Submit" runat="server"OnClientClick="ClearFileUploadControl()" /></td></tr>
</table>
</div>
</form>
</body>
</html>

1 comment:

  1. Runs on Local machine perfectly...but after publishing to the server it doesn't works...

    ReplyDelete