Asyncfileupload 文件预览不显示
我在更新面板中有一个 Ajax 异步文件上传控件。我的上传工作正常,但上传完成后,我需要查看我上传的图像。 但它在这里不起作用,这是我所做的
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
OnUploadedComplete
事件来显示图像。有关如何显示预览的详细信息,请查看以下示例:使用 AsyncFileUpload 控件在 ASP.NET 中上传 AJAX 文件
You can use the
OnUploadedComplete
event to display the image.For Details on how to show the preview take a look at this example: AJAX File Upload in ASP.NET with the AsyncFileUpload Control
我认为“~”不适用于 HTML 控件。尝试将路径转换为实际路径并设置图像源。
I don't think "~" will work with HTML controls. Try converting the path to actual path and set the Image src.