jquery模式弹出窗口中的asyncfileupload

时间:2011-12-04 12:31:15

标签: asp.net jquery-ui ajaxcontroltoolkit asyncfileupload

我已经在jquery模式弹出窗口上放置了一个AsyncFileUpload控件,并且我无法在上传时触发“AsyncFileUpload1_UploadedComplete”。

直接放在页面上时可以正常工作。 (顺便说一下,这都在主页上)

相关代码

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>

    <script type="text/javascript" language="javascript">

    function uploadError(sender, args) {
        alert(args.get_errorMessage());
        document.getElementById('<%=lblStatus.clientid %>').innerText = args.get_fileName(), "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
    }

    function StartUpload(sender, args) {
        document.getElementById('<%=lblStatus.clientid %>').innerText = 'Uploading Started.';
    }

    function UploadComplete(sender, args) {
        var filename = args.get_fileName();
        var contentType = args.get_contentType();
        var text = filename + " has been uploaded successfully. Size: " + args.get_length() + " bytes";
        document.getElementById('<%=lblStatus.clientid %>').innerText = text;
    }

</script>

       <cc2:AsyncFileUpload ClientIDMode="AutoID" ID="AsyncFileUpload1" runat="server" OnClientUploadError="uploadError"
                    OnClientUploadStarted="StartUpload" OnClientUploadComplete="UploadComplete" CompleteBackColor="Lime"
                    UploaderStyle="traditional" ErrorBackColor="Red" ThrobberID="Throbber" OnUploadedComplete="AsyncFileUpload1_UploadedComplete"
                    UploadingBackColor="#66CCFF" />
                <asp:Label ID="Throbber" runat="server" Style="display: none">
                            <img src="images/icons/ajax-loader.gif" style="vertical-align:middle"  alt="loading" />
                </asp:Label>&nbsp;
                <asp:Label ID="lblStatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label>

就像我说的那样直接放在母版页上时可以正常工作,但是当放置一个div作为模态弹出窗口时不起作用。 我有顺便说一下

<form id="Form1" runat="server" enctype="multipart/form-data" method="post">

背后的代码:

Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
    If AsyncFileUpload1.HasFile Then
        txtRef.Text = "1234"
        If IO.Directory.Exists(Server.MapPath("~\uploads\" & txtRef.Text)) = False Then
            IO.Directory.CreateDirectory(Server.MapPath("~\uploads\" & txtRef.Text))
        End If
        Dim strPath As String = MapPath("~/Uploads/" & txtRef.Text & "/") & IO.Path.GetFileName(e.FileName)
        AsyncFileUpload1.SaveAs(strPath)
        Dim attach As New attachment
        attach.CallID = txtRef.Text
        attach.Filename = IO.Path.GetFileName(e.filename)
        attach.Ext = System.IO.Path.GetExtension(e.filename)
        attach.UserID = Session("user_id")
        attach.Create()
    End If
End Sub

在表单标签中但仍然没有运气,我已将ajaxtoolkit升级到最新版本。

有什么想法吗?

谢谢,

1 个答案:

答案 0 :(得分:2)

这是因为jQuery从表单中删除了控件,并在创建对话框时将其放在正文的末尾。当它提交表单时,AsyncFileUpload控件不再在表单中,因此没有任何内容可以回发到服务器以进行此控件,这就是为什么它不会将文件发回。 你需要做的是在jQuery创建它之后将对话框div放回到表单中。

        $('#yourDialogID').parent().appendTo('form');