<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true"> <contenttemplate> <asp:AsyncFileUpload ID="abcd1" runat="server" Height="25px" Width="242px" OnClientUploadComplete="uploadComplete" ThrobberID="imgLoader" OnClientUploadStarted="uploadStarted" OnClientUploadError="uploadError" /> <asp:Button ID="btnUpload" runat="server" Text="Upload" onclick="btnUpload_Click1" /> </contenttemplate> <triggers> <asp:PostBackTrigger ControlID="btnUpload" /> </triggers> </div>
<script type="text/javascript" language="javascript"> function uploadError(sender, args) { document.getElementById('lblStatus').innerText = args.get_fileName(), "<span style="color:red;">" + args.get_errorMessage() + "</span>"; } function StartUpload(sender, args) { document.getElementById('lblStatus').innerText = 'Uploading Started.'; } function UploadComplete(sender, args) { var filename = args.get_fileName(); var contentType = args.get_contentType(); var text = "Size of " + filename + " is " + args.get_length() + " bytes"; if (contentType.length > 0) { text += " and content type is '" + contentType + "'."; } document.getElementById('lblStatus').innerText = text; } </script>
protected void btnUpload_Click1(object sender, EventArgs e) { try { HttpFileCollection uploadFiles = Request.Files; for (int i = 0; i < uploadFiles.Count; i++) { HttpPostedFile uploadFile = uploadFiles[i]; string fileName = Path.GetFileName(uploadFile.FileName); if (fileName.Trim().Length > 0) { uploadFile.SaveAs(Server.MapPath("~/Files/") + fileName); lblStatus.Text = "File Uploaded Successfully"; } } } catch (Exception ex) { lblStatus.Text = "Error in uploading file"; } }
onuploadedcomplete
<triggers> <asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" /> </triggers>
<triggers> <asp:PostBackTrigger ControlID="btnUpload" /> </triggers>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)