简体   繁体   English

AsyncPostBackTrigger没有更新更新面板

[英]AsyncPostBackTrigger is not updating the update panel

I am using an update panel inside a user control in ASP.NET (.ascx file). 我在ASP.NET(.ascx文件)的用户控件内使用更新面板。 Below is my HTML markup 以下是我的HTML标记

<asp:ScriptManager EnablePartialRendering="true"
                   ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>        
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" >
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" /><br />
            <asp:Button ID="Button1" runat="server" Text="Update Panel" OnClick="Button1_Click" />                
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click">
           </asp:AsyncPostBackTrigger>
        </Triggers>
    </asp:UpdatePanel>
</div>

here is my code-behind 这是我的代码背后

public partial class sample: System.Web.UI.Control
{
    protected void Button1_Click(object sender, EventArgs e)
    {

        Label1.Text = DateTime.Now.ToLongTimeString();
        UpdatePanel1.Update();
    }

}

If I use PostBackTrigger, then it works fine but posts back the entire page (that's something I don't want) I just need to refresh the update panel. 如果我使用PostBackTrigger,那么它可以正常工作,但是回发整个页面(这是我不想要的),我只需要刷新更新面板即可。

And here is my aspx page markup (it's Sitecore driven site so all the sublayouts are loaded into Sitecore placeholders) 这是我的aspx页面标记(它是Sitecore驱动的网站,因此所有子布局都加载到Sitecore占位符中)

<form id="form2" runat="server">
    <section class="page">
        <sc:Placeholder runat="server" ID="mainPlaceholder" Key="content" />
    </section>
</form>

I'm sorry, cannot post the entire page due to some security reasons 抱歉,由于某些安全原因,无法发布整个页面

Thank you 谢谢

a few things to try. 一些尝试。 (it works fine for me.) (这对我来说可以。)

  1. make sure you do not have 2 script managers, one on the page and one on the control. 确保您没有2个脚本管理器,一个在页面上,一个在控件上。 one on the aspx page is enough. aspx页面上的一个就足够了。
  2. delete the user control from the aspx page and add the user control again. 从aspx页面删除用户控件,然后再次添加用户控件。 drag your user control to the aspx page to make sure it's registered at the top of the page. 将您的用户控件拖到aspx页面上,以确保它已在页面顶部注册。
  3. remove the triggers; 删除触发器; you don't need them. 您不需要它们。

you are also setting some properties that are equal to the default values so you can remove them: 您还设置了一些等于默认值的属性,因此可以将其删除:

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

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" /><br />
        <asp:Button ID="Button1" runat="server" Text="Update Panel"
            OnClick="Button1_Click" />                
    </ContentTemplate>
</asp:UpdatePanel>

protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToLongTimeString();
    //UpdatePanel1.Update();
}

Finally, I found a solution to fix this issue. 最后,我找到了解决此问题的解决方案。 My entire HTML markup remains same just need to comment or take off the triggers. 我的整个HTML标记保持不变,只需要注释或删除触发器即可。 I just commented the inner HTML of tag and it everything worked as expected. 我只是评论了标签的内部HTML,它一切都按预期工作。

You should use AJAX postbacks which won't send the whole page and will just update the panel. 您应该使用AJAX回传,它不会发送整个页面,而只会更新面板。 See this article https://docs.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-getting-started/aspnet-ajax/understanding-partial-page-updates-with-asp-net-ajax 请参阅本文https://docs.microsoft.com/zh-cn/aspnet/web-forms/overview/older-versions-getting-started/aspnet-ajax/understanding-partial-page-updates-with-asp-net -ajax

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

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