为什么更新面板会对自定义控件进行完整回发?

发布于 2024-07-15 04:06:42 字数 659 浏览 2 评论 0原文

我有一个相当复杂的自定义控件 - 自定义控件中有几个更新面板。

我正在尝试在更新面板中使用这样的控件:

    <asp:UpdatePanel ID="up1" runat="server">
    <ContentTemplate>
     <asp:Button ID="btn1" runat="server" Text="Sample Button" />&nbsp;&nbsp;<asp:Label ID="lblTime" runat="server"></asp:Label>    
     <cc1:MyCustomControl ID="MyCustomControl1" runat="server" >
    </cc1:MyCustomControl>
    </ContentTemplate>
</asp:UpdatePanel>

当我单击更新面板中的按钮时,它会执行异步回发,并且没有屏幕“闪烁”当我单击自定义控件中的按钮时,页面闪烁并进行完整的回发。

在自定义控件内部,有一些更新面板正在尝试执行完整的回发(基于触发器)。

如何使页面级 UpdatePanel 不执行完整回发,无论自定义控件内部发生什么?

I have a rather complex custom control - the custom control has a couple of update panels in it.

I am trying to use the control like this inside of an update panel:

    <asp:UpdatePanel ID="up1" runat="server">
    <ContentTemplate>
     <asp:Button ID="btn1" runat="server" Text="Sample Button" />  <asp:Label ID="lblTime" runat="server"></asp:Label>    
     <cc1:MyCustomControl ID="MyCustomControl1" runat="server" >
    </cc1:MyCustomControl>
    </ContentTemplate>
</asp:UpdatePanel>

When I click the button in the update panel, it does an async post back and there is no screen "flicker" When I click a button in my custom control the page flickers and does a full post back.

Inside the custom control, there are update panels that are trying to do full postbacks (based on triggers).

How can I make the page level UpdatePanel not do a full postback no matter what is going in inside of the custom control?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猥琐帝 2024-07-22 04:06:42

您是否考虑过使用 up1 UpdatePanel 控件中的 btn1 控件显式设置 asp:AsyncPostBackTrigger。

<asp:UpdatePanel ID="up1" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
    </Triggers>
    <ContentTemplate>     
        <asp:Button ID="btn1" runat="server" Text="Sample Button" />  
        <asp:Label ID="lblTime" runat="server"></asp:Label>         
        <cc1:MyCustomControl ID="MyCustomControl1" runat="server" />                 
    </ContentTemplate>
</asp:UpdatePanel>

编辑:您如何尝试在更新面板的按钮 OnClick 事件中显式调用 Update 方法? 这包括嵌入自定义控件中的更新面板。

Have you thought about explicitly setting an asp:AsyncPostBackTrigger with the btn1 control in the up1 UpdatePanel control.

<asp:UpdatePanel ID="up1" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
    </Triggers>
    <ContentTemplate>     
        <asp:Button ID="btn1" runat="server" Text="Sample Button" />  
        <asp:Label ID="lblTime" runat="server"></asp:Label>         
        <cc1:MyCustomControl ID="MyCustomControl1" runat="server" />                 
    </ContentTemplate>
</asp:UpdatePanel>

Edit: How you tried to explicitly call the Update method in the button's OnClick event for the Update Panel? This includes the Update panels embedded within the custom control.

酒解孤独 2024-07-22 04:06:42

找出与此类似的问题的解决方案:如何我可以让 UpdatePanel 拦截 CompositeControl 的 DropDownList

除了导致回发的控件位于具有完整回发触发器的 updatepanel 中。 我能够将该控件拉出来,这样它就不会嵌套在更新面板中,从而解决了这个问题。

Figured out the solution similar issue to this: How can I get an UpdatePanel to intercept a CompositeControl's DropDownList

Except my control causing the postback was in an updatepanel with a full postback trigger. I was able to pull that control out so it was not nested with in update panels and that resolved it.

爱冒险 2024-07-22 04:06:42

我首先会看看自定义控件是否存在其他问题导致整页回发,因为无论如何,应该发生的是整个更新面板刷新(仍然使用ajax)。

之后,只需查看嵌套 UpdatePanel 控件部分即可:
http://msdn.microsoft.com/en-us/library/bb398867 .aspx#

还要确保 ScriptManager 控件的属性 EnablePartialRendering 设置为 true。

I would first look if there is some other issue with the custom control causing the full page postback, as in any case what should be happening is that the whole update panel refreshes (still with ajax).

After that, just look at the Nesting UpdatePanel Controls section of this:
http://msdn.microsoft.com/en-us/library/bb398867.aspx#

Also make sure to have the ScriptManager control with the property EnablePartialRendering set to true.

盛夏已如深秋| 2024-07-22 04:06:42

在 UpdatePanel 上,设置属性 ChildrenAsTriggers="true"。 这告诉 UpdatePanel 拦截源自 UpdatePanel 内部的所有 PostBack 调用。

您可能还想探索 UpdateMode 属性,它确定什么类型事件触发更新。 (默认情况下,如果屏幕上的任何其他面板刷新,UpdatePanel 也会刷新。这让我困惑了一段时间,直到我意识到发生了什么。)

On the UpdatePanel, set the property ChildrenAsTriggers="true". This tells the UpdatePanel to intercept all PostBack invocations that originate from inside the UpdatePanel.

You may want to also explore the UpdateMode property, which determines what kinds of events trigger an update. (By default, an UpdatePanel will refresh if any other panel on the screen gets refreshed. This threw me for awhile until I realized what was going on.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文