本文介绍了Asyncfileupload文件预览不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在更新面板中有一个Ajax异步文件上传控件.我的上传工作正常,但是上传完成后,我需要查看上传的图像.但这不行,这是我所做的
I am having an Ajax Asynchronous file upload control in update panel. My upload works fine but after the upload is completed., I need to see the image I have uploaded.But it doesnt work here is what I have done
function UploadComplete(sender, args) {
var filename = args.get_fileName();
var contentType = args.get_contentType();
if (contentType.indexOf('image') == -1) {
document.getElementById('<%=lblStatus.ClientID%>').innerText = "Uploaded file must be an Image!"+ "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
document.getElementById('<%=AsyncFileUpload1.ClientID%>').text.style.backgroundColor = "Red";
}
else {
var text = "" + filename + " | " + args.get_length() + " bytes"+"Uploaded Succesfully";
document.getElementById('<%=lblStatus.ClientID%>').innerText = text;
$get("imageView1").src = "./~/" + filename;
}
}
AspCode:
<ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" Width="400px" runat="server"
OnClientUploadError="uploadError"
OnClientUploadStarted="StartUpload"
OnClientUploadComplete="UploadComplete"
CompleteBackColor="Lime" UploaderStyle="Modern"
ErrorBackColor="Red" ClientIDMode="AutoID"
ThrobberID="Throbber"
UploadingBackColor="#66CCFF"
onuploadedcomplete="AsyncFileUpload1_UploadedComplete" />
<asp:Label ID="Throbber" runat="server" Style="display: none">
<asp:Image runat="server" ID="imgPreview" ImageUrl="~/Images/uploading.gif" />
</asp:Label>
<img runat="server" id="imageView1"/>
<asp:Label ID="lblStatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label>
推荐答案
您可以使用 OnUploadedComplete
事件显示图像.
You can use the OnUploadedComplete
event to display the image.
<ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" Width="400px" runat="server" OnUploadedComplete="ProcessUpload"
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string fileName = Server.MapPath("./") + "image.jpg";
AsyncFileUpload1.SaveAs(fileName);
ScriptManager.RegisterClientScriptBlock(AsyncFileUpload1, AsyncFileUpload1.GetType(), "img",
"top.document.getElementById('imgUpload').src='image.jpg';",
true);
}
有关如何显示预览的详细信息,请看以下示例:使用AsyncFileUpload控件在ASP.NET中上传AJAX文件
For Details on how to show the preview take a look at this example: AJAX File Upload in ASP.NET with the AsyncFileUpload Control
这篇关于Asyncfileupload文件预览不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!