简体   繁体   English

updatepanel.update()似乎没有从隐藏代码中触发

[英]updatepanel.update() doesn't appear to fire from code-behind

I have an updatepanel that I change the content of and then call updatepanel.update() to asynchronously update that section of the page, but it does not appear to fire the update() from the code-behind (ie. the Async Post Back doesn't happen and doesn't display the updated content. 我有一个updatepanel,可以更改其内容,然后调用updatepanel.update()异步更新页面的该部分,但是它似乎不会从后台代码中触发update()(即,异步回发)不会发生,也不会显示更新的内容。

The following scriptmanager is in a MasterPage: 以下脚本管理器位于MasterPage中:

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true" ></asp:ToolkitScriptManager>

The page in question has the following update panel: 有问题的页面具有以下更新面板:

<asp:UpdatePanel ID="upImageConfirm" runat="server" UpdateMode="always">
    <ContentTemplate>
        <div id="imageContainer">
            <asp:label ID="lblCheckPackshot" runat="server" Text="None" />
            <asp:button ID="btnLoadPackshot" runat="server" OnClick="uploadPackShot" Text="Upload &raquo;" />
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

The following codebehind is kicked off and run when a file upload is complete (checking in debugging this code does run and does change the values, but the update isn't fired: 文件上传完成后,下面的代码将启动并运行(签入调试此代码确实会运行并且会更改值,但不会触发更新:

protected void uploadComplete(object sender, jaxControlToolkit.AsyncFileUploadEventArgs e)
{
try
{
            //upload file to web file system
            if (afuStockImport.HasFile)
            {
                string strPath = Server.MapPath("~/graphics/holding/") + Path.GetFileName(afuStockImport.PostedFile.FileName);
                Session["uploadedFileName"] = afuStockImport.PostedFile.FileName;
                afuStockImport.SaveAs(strPath);

                //Show on page for confirmation
                lblCheckPackshot.Text = "<img src=\"/graphics/holding/" + Path.GetFileName(afuStockImport.PostedFile.FileName) + "\" />";
                upImageConfirm.Update();
            }
        }
}

Thanks! 谢谢!

This is a behavior with the AsyncFileUpload from ASP.NET AJAX Toolkit. 这是来自ASP.NET AJAX工具包的AsyncFileUpload的行为。 The problem is that the AsyncFileUpload use a iframe to handle the asynchronous upload, so the "page" that raise the uploadComplete event and the the client page is not linked the same way as usual. 问题在于AsyncFileUpload使用iframe来处理异步上传,因此引发uploadComplete事件和客户端页面的“页面”与通常的链接方式不同。

On workaround for that is to use the OnClientUploadComplete event to trigger an asyncpostback using javascript and then update your updatepanel. 解决方法是使用OnClientUploadComplete事件使用javascript触发asyncpostback,然后更新您的updatepanel。 There is many others way of doing this, some are not using an update panel . 有许多其他方式可以做到这一点, 有些没有使用更新面板

Technically you can't do Async file uploads. 从技术上讲,您不能上传异步文件。 The implementations that exist are all workarounds...hidden IFrames, TextAreas...etc 存在的实现都是解决方法...隐藏的IFrame,TextAreas等

Why don't file uploads work during async postbacks? 为什么文件上传在异步回发期间不起作用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM