asyncfileupload jQuery的模态弹出 [英] asyncfileupload in jquery modal popup

查看:141
本文介绍了asyncfileupload jQuery的模态弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经放在一个jQuery模态弹出一个AsyncFileUpload控制,我不能在AsyncFileUpload1_UploadedComplete火OK时上传

I have placed an AsyncFileUpload control on a jquery modal popup and I can't the "AsyncFileUpload1_UploadedComplete" to fire when ok to upload.

它在页面上直接放在工作。 (这是所有通过的方式母版)

It does work when placed directly on the page. (This is all on a masterpage by the way)

培训相关code是

<%@ 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这是一个模式弹出放置不起作用。
我也顺便说一句集

Like I say does work when placed on masterpage directly , but doesn't work when placed with a div which is to be a modal popup. I have btw set

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

在code背后:

The code behind:

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到最新版本。

in the form tags but still no luck and I have upgraded ajaxtoolkit to the latest.

任何想法?

谢谢,

推荐答案

此发生因为jQuery将删除的形式控制,当它创建对话框把它在本体的端部。当提交表单时,AsyncFileUpload控制形式不再,所以没有什么可回发到服务器此控件,这就是为什么它不张贴回文件。
你需要做的就是把对话框的div回形式jQuery的创建后。

This happens because jQuery removes the control from the form and puts it at the end of the body when it creates the dialog. When it submits the form, the AsyncFileUpload control is no longer in the form, so there is nothing to postback to the server for this control and that's why it is not posting the file back. What you need to do is put the dialog div back into the form after jQuery creates it.

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

这篇关于asyncfileupload jQuery的模态弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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