Asp.net中的Ajax AsynchFileUpload [英] Ajax AsynchFileUpload in Asp.net

查看:85
本文介绍了Asp.net中的Ajax AsynchFileUpload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net页面中使用了AsychFileUpload,

使用以下代码上传

I used AsychFileUpload in my asp.net page,

Used the following code to upload

protected void FupFoto_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        System.Threading.Thread.Sleep(5000);
        if (FupFoto.HasFile)
        {
            string strPath = MapPath("~/EmpImages/") + Path.GetFileName(e.filename);
            
            FupFoto.SaveAs(strPath);
            ImgFoto.ImageUrl = strPath;

        }
    }



执行FupFoto.SaveAs(strPath)时出现错误,但是文件正在上传到指定的文件夹,但是ImgFoto没有随文件一起加载

错误是
"There is no source code available for the current location"

我什么也没说.

请帮助我



When executing FupFoto.SaveAs(strPath), I am getting an error, But the file is uploading to the specified folder, But the ImgFoto is not loading with the file

The Error is
"There is no source code available for the current location"

I can''t get anything detailed.

Please help me

推荐答案

尝试一下.

Try this.

ImgFoto.ImageUrl = "~/EmpImages/" + Path.GetFileName(e.filename);


您好


此错误

Hi


This error

The Error is
"There is no source code available for the current location"



是因为您没有脚本管理器.

例如...

aspx内容..



is due to you are not having a script manager.

As an example...

the aspx content..

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <script type="text/javascript" language="javascript">
            function Test(sender,e) {
                alert("EmpImages/" + e.get_fileName());
                document.getElementById('<%=ImgFoto.ClientID %>').src = "EmpImages/" + e.get_fileName();
            }
         </script>
            <asp:AsyncFileUpload ID="FupFoto" runat="server"   OnClientUploadComplete="Test"      ClientIDMode="AutoID"   OnUploadedComplete="FupFoto_UploadedComplete"/>
            <asp:Image  ID="ImgFoto" runat="server"    ImageUrl=""  />
</asp:Content>




在上传完成事件中...




in the upload complete event...

protected void FupFoto_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    if (FupFoto.HasFile)
    {
        string strPath = MapPath("~/EmpImages/") + Path.GetFileName(e.filename);
        FupFoto.SaveAs(strPath);
    }
}




在此示例中应该可以正常工作




it should be working in this example


这篇关于Asp.net中的Ajax AsynchFileUpload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆