Home > .Net > AJAX Toolkit File upload asynch asp:AsyncFileUpload

AJAX Toolkit File upload asynch asp:AsyncFileUpload

It is perfect control if you don’t have to update any label or gridview in it .cs method. It perfectly did any DB operations but won’t update the html.

<asp:AsyncFileUpload OnClientUploadError=”uploadError” OnClientUploadComplete=”uploadComplete”

runat=”server” ID=”AsyncFileUpload1″ Width=”400px” CompleteBackColor=”White”

UploadingBackColor=”#CCFFFF” ThrobberID=”imgLoader” OnUploadedComplete=”FileUploadComplete”

FailedValidation=”False” />

<asp:Image ID=”imgLoader” runat=”server” ImageUrl=”~/images/loader.gif” />

<br />

<asp:Label ID=”lblMesg” runat=”server”></asp:Label>

FileUploadComplete method:

string strfilename = System.IO.Path.GetFileName(AsyncFileUpload1.PostedFile.FileName);

string strFullPath = Server.MapPath(Constants.General.RequestAttachmentsFolderName + lblRequestID.Text + “/”);

if (!System.IO.Directory.Exists(strFullPath))

{

System.IO.Directory.CreateDirectory(strFullPath);

}

AsyncFileUpload1.SaveAs(strFullPath + strfilename);

JavaScript:

<script type=”text/javascript”>

function uploadComplete(sender) {

$get(“<%=lblMesg.ClientID%>”).style.color = “green”;

$get(“<%=lblMesg.ClientID%>”).innerHTML = “File Uploaded Successfully”;

clearContents();

–alert(‘before’);

__doPostBack(‘<%= Button1.ClientID %>’, ”);

–alert(‘after’);

}

function uploadError(sender) {

$get(“<%=lblMesg.ClientID%>”).style.color = “red”;

$get(“<%=lblMesg.ClientID%>”).innerHTML = “File upload failed.”;

}

function clearContents() {

var AsyncFileUpload = $get(“<%=AsyncFileUpload1.ClientID%>”);

var txts = AsyncFileUpload.getElementsByTagName(“input”);

for (var i = 0; i < txts.length; i++) {

if (txts[i].type == “text”) {

txts[i].value = “”;

txts[i].style.backgroundColor = “white”;

}

}

}

</script>

Useful links

http://www.aspsnippets.com/Articles/Using-ASP.Net-AJAX-Control-Toolkits-AsyncFileUpload-Control.aspx

http://www.aspsnippets.com/Blue/Articles/Clear-contents-of-AsyncFileUpload-Control-after-upload-and-page-revisit.aspx

http://www.codeproject.com/Articles/42865/AsyncFileUpload-Control-New-Control-in-Ajax-Contro

http://www.asp.net/ajaxlibrary/HOW%20TO%20Use%20the%20AsyncFileUpload%20Control.ashx

Comments are closed.

TOP