自定义服务器控制导致 UpdatePanel 内部完全回发

发布于 2024-07-22 09:20:41 字数 663 浏览 7 评论 0原文

我有一个自定义服务器控件,在我将其放入 UpdatePanel 之前,它似乎工作正常。 一旦进入 UpdatePanel,它就可以继续正常工作,但是当我的自定义服务器控件执行回发时,UpdatePanel 现在会执行完整的回发。

我是否需要执行任何操作才能使自定义服务器控件在 UpdatePanel 内执行异步回发?

这是导致完整回发的相关代码。 ecs:Pager 控件是我的自定义控件,即使它位于 UpdatePanel 中,也会导致 OnCommand 事件的完全回发。

<asp:UpdatePanel ID="ClosedIssuesUpdatePanel" runat="server">
    <ContentTemplate>
        <ecs:Pager ID="ClosedIssuesPager" OnCommand="ClosedIssuesPager_Command" runat="server" />
        <asp:Repeater ID="ClosedIssuesRepeater" runat="server">
        ....
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>

I have a custom server control that seems to work fine until I put it in an UpdatePanel. Once inside the UpdatePanel it continues to work fine but the UpdatePanel now does full postbacks when my custom server control does a postback.

Do I need to do anything to make my custom server control do async postbacks while inside an UpdatePanel?

Here is the relevant code that is causing a full postback. The ecs:Pager control is my custom control that causes full postbacks on the OnCommand event even though it is in the UpdatePanel.

<asp:UpdatePanel ID="ClosedIssuesUpdatePanel" runat="server">
    <ContentTemplate>
        <ecs:Pager ID="ClosedIssuesPager" OnCommand="ClosedIssuesPager_Command" runat="server" />
        <asp:Repeater ID="ClosedIssuesRepeater" runat="server">
        ....
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>

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

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

发布评论

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

评论(6

别理我 2024-07-29 09:20:41

将更新面板的更新模式设置为有条件。

<asp:UpdatePanel ID="ClosedIssuesUpdatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <ecs:Pager ID="ClosedIssuesPager" OnCommand="ClosedIssuesPager_Command" runat="server" />
        <asp:Repeater ID="ClosedIssuesRepeater" runat="server">
        ....
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>

Put the update mode of your update panel to conditional.

<asp:UpdatePanel ID="ClosedIssuesUpdatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <ecs:Pager ID="ClosedIssuesPager" OnCommand="ClosedIssuesPager_Command" runat="server" />
        <asp:Repeater ID="ClosedIssuesRepeater" runat="server">
        ....
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>
驱逐舰岛风号 2024-07-29 09:20:41

您没有指定自定义控件中使用的控件类型。 它们是按钮、下拉菜单还是其他东西? 如果它们是按钮,您需要确保它们的 UseSubmitBehavior 属性设置为 False。

另外,您还需要通过 ScriptManager.RegisterAsyncPostBackControl

You don't specify what kind of controls are being used in your custom control. Are they buttons or drop downs or something else? If they're buttons, you need to make sure that their UseSubmitBehavior properties are set to False.

Also, you're going to want to register your controls with the page's ScriptManager via ScriptManager.RegisterAsyncPostBackControl

厌倦 2024-07-29 09:20:41

我遇到了类似的问题,发现将属性 ClientIDMode="AutoID" 添加到我的用户控件标记解决了问题。

I had a similar problem and found that adding the attribute ClientIDMode="AutoID" to my user control tag solved the problem.

甩你一脸翔 2024-07-29 09:20:41

抱歉...看不到页面的其余部分。

您的页面上也有 ScriptManager 吗?

Sorry...can't see the rest of the page.

Do you have a ScriptManager on your page, as well?

影子是时光的心 2024-07-29 09:20:41

自定义控件是否实现 INamingContainer,并且回发是否来自该命名容器内的另一个控件?

我发现 UpdatePanel 和源代码管理之间的命名容器边界可能会导致此行为。

Does the custom control implement INamingContainer, and is the postback coming from another control inside that naming container?

I found a naming container boundary between the UpdatePanel and the source control can cause this behavior.

顾冷 2024-07-29 09:20:41

一种选择可能是像 AndreasKnudsen 建议的那样将 AsyncPostBackTrigger 添加到您的面板

<asp:UpdatePanel ID="ClosedIssuesUpdatePanel" runat="server">
  <ContentTemplate>
    <ecs:Pager ID="ClosedIssuesPager" OnCommand="ClosedIssuesPager_Command" runat="server" />
    <asp:Repeater ID="ClosedIssuesRepeater" runat="server">
      ....
    </asp:Repeater>
  </ContentTemplate>
  <Triggers>
    <AsyncPostBackTrigger ControlID="ClosedIssuesPager" EventName="Command" />
  </Triggers>
</asp:UpdatePanel>

另一种选择是尝试将 ChildrenAsTriggers 添加到您的 UpdatePanel 标记

<asp:UpdatePanel ID="ClosedIssuesUpdatePanel" runat="server" ChildrenAsTriggers="true">

One option might be as AndreasKnudsen suggests as adding an AsyncPostBackTrigger to your panel

<asp:UpdatePanel ID="ClosedIssuesUpdatePanel" runat="server">
  <ContentTemplate>
    <ecs:Pager ID="ClosedIssuesPager" OnCommand="ClosedIssuesPager_Command" runat="server" />
    <asp:Repeater ID="ClosedIssuesRepeater" runat="server">
      ....
    </asp:Repeater>
  </ContentTemplate>
  <Triggers>
    <AsyncPostBackTrigger ControlID="ClosedIssuesPager" EventName="Command" />
  </Triggers>
</asp:UpdatePanel>

Another option is to try adding ChildrenAsTriggers to your UpdatePanel tag

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