AsyncFileUploadWithAjaxToolKit无效

时间:2013-08-30 08:23:31

标签: asp.net

大家好,我使用以下代码进行上传:

HTML:
 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

        <cc1:AsyncFileUpload ID="AsyncFileUpload1" Width="400px" runat="server"
            OnClientUploadError="uploadError"
            OnClientUploadStarted="StartUpload"
            OnClientUploadComplete="UploadComplete"
            CompleteBackColor="Lime" UploaderStyle="Modern"
            ErrorBackColor="Red"
            ThrobberID="Throbber"
            OnUploadedComplete="AsyncFileUpload1_UploadedComplete"
            UploadingBackColor="#66CCFF" />

        <asp:Label ID="Throbber" runat="server" Style="display: none">
        <img src="Images/indicator.gif" align="absmiddle" alt="loading" />
        </asp:Label>
        <br />
        <br />
        <asp:Label ID="lblStatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label>

我的java脚本代码是:

 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;
    }

我的服务器幻灯片脚本:

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        System.Threading.Thread.Sleep(5000);
        if (AsyncFileUpload1.HasFile)
        {
            string strPath = MapPath("~/Uploads/") + Path.GetFileName(e.FileName);
            AsyncFileUpload1.SaveAs(strPath);
        }

    }

我有以下错误:

  
    

无法加载资源:服务器响应状态为404(未找到)Scripts / WebForms / MsAjax / MicrosoftAjaxWebForms.js失败     加载资源:服务器响应状态为404(未找到)     Scripts / WebForms / MsAjax / MicrosoftAjax.js未捕获错误:ASP.NET Ajax     客户端框架无法加载。 test.aspx:72未捕获     ReferenceError:未定义Sys test.aspx:84未捕获     ReferenceError:未定义Sys test.aspx:105未捕获     ReferenceError:未定义Sys

  

我第一次使用这个conrotl plz帮我感谢了很多。

1 个答案:

答案 0 :(得分:1)

您需要使用EnablePageMethods =“true”属性标记ScriptManager才能使其生效

例如:

<asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true">
</asp:ScriptManager>