Updatepanel 提供完整回发而不是异步回发

发布于 2024-10-05 06:10:51 字数 1772 浏览 0 评论 0原文

我遇到了一个似乎非常著名的问题:我的 updatepanel 触发完整回发而不是异步回发。正常的解决方案是为所有动态添加的控件提供一个 ID,我已经这样做了,但我仍然得到完整的回发而不是异步回发...

代码如下:

HTML:

<asp:UpdatePanel ID="ItemsUpdatePanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
   <Triggers>
   </Triggers>    
   <ContentTemplate>
   <asp:ListView ID="PlayerItems" runat="server" GroupItemCount="5" 
                                    onitemdatabound="PlayerItems_ItemDataBound">
   <LayoutTemplate>

   ... Listview stuff ...

    </asp:ListView> 

    </ContentTemplate>
</asp:UpdatePanel>

有趣的部分是后面的 C# 代码(方法PlayerItems_ItemDataBound),如下所示:

            ImageButton imgBtn = new ImageButton();
            imgBtn.ID = "itemBtn";
            imgBtn.Width = Unit.Pixel(30);
            imgBtn.ImageUrl = "~/Images/Game/Items/" + myItem.ItemImageUrl;

            ContextMenu menu = new ContextMenu();
            menu.BoundControls.Add(imgBtn);
            menu.ItemCommand += new CommandEventHandler(menu_ItemCommand);

            menu.AutoHide = true;
            menu.RolloverColor = Color.Gray;
            menu.ID = "MenuMenu";

            Panel panel = (Panel)(e.Item.FindControl("ItemPanel"));
            panel.Controls.Add(imgBtn);
            panel.Controls.Add(menu);

            AsyncPostBackTrigger trig = new AsyncPostBackTrigger();
            trig.ControlID = menu.UniqueID;
            trig.EventName = "ItemCommand";
            ItemsUpdatePanel.Triggers.Add(trig);

所以,我实际上向菜单添加了一个 AsyncPostBackTrigger,因此应该注册 ItemCommand 事件。当我单击此上下文菜单中的某个项目时,会发生完整的回发。

我一直在尝试在没有帮助的情况下使用 ChildrenAsTriggers 属性。我还上下移动了 AsyncPostBackTrigger 代码,同样没有帮助。

预先非常感谢..! 拉尔斯

I have run into what seems to be a very famous problem: My updatepanel fires a full postback instead of a async postback. The normal solution is to give all controls you add dynamically an ID, which I have done, but I still get a full postback instead of my async postback...

Here's the code:

HTML:

<asp:UpdatePanel ID="ItemsUpdatePanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
   <Triggers>
   </Triggers>    
   <ContentTemplate>
   <asp:ListView ID="PlayerItems" runat="server" GroupItemCount="5" 
                                    onitemdatabound="PlayerItems_ItemDataBound">
   <LayoutTemplate>

   ... Listview stuff ...

    </asp:ListView> 

    </ContentTemplate>
</asp:UpdatePanel>

The interesting part is the C# code behind (method PlayerItems_ItemDataBound), which is like the following:

            ImageButton imgBtn = new ImageButton();
            imgBtn.ID = "itemBtn";
            imgBtn.Width = Unit.Pixel(30);
            imgBtn.ImageUrl = "~/Images/Game/Items/" + myItem.ItemImageUrl;

            ContextMenu menu = new ContextMenu();
            menu.BoundControls.Add(imgBtn);
            menu.ItemCommand += new CommandEventHandler(menu_ItemCommand);

            menu.AutoHide = true;
            menu.RolloverColor = Color.Gray;
            menu.ID = "MenuMenu";

            Panel panel = (Panel)(e.Item.FindControl("ItemPanel"));
            panel.Controls.Add(imgBtn);
            panel.Controls.Add(menu);

            AsyncPostBackTrigger trig = new AsyncPostBackTrigger();
            trig.ControlID = menu.UniqueID;
            trig.EventName = "ItemCommand";
            ItemsUpdatePanel.Triggers.Add(trig);

So, I actually add an AsyncPostBackTrigger to the menu, so the ItemCommand event should be registered. What happends when I click an item in this contextmenu, is a full postback happends.

I have been trying to play with the ChildrenAsTriggers property without help. I have also been moving the AsyncPostBackTrigger code up and down, also without help.

Thanks a lot beforehand..!
Lars

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

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

发布评论

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

评论(2

标点 2024-10-12 06:10:51

在 UpdatePanel 的面板内的 ListView 内填充 CheckBoxList 时,我也有同样的经历。通过在 CheckBoxList 中添加以下代码解决了这个问题:

ClientIDMode="AutoID" 

I had the same experience when populating a CheckBoxList inside a ListView inside a Panel in an UpdatePanel. It was solved by adding this code in the CheckBoxList:

ClientIDMode="AutoID" 
反话 2024-10-12 06:10:51

来自 AsyncPostBackTrigger 文档:

以编程方式添加
AsyncPostBackTrigger 控件不是
支持。
以编程方式
注册一个回发控件,使用
RegisterAsyncPostBackControl 方法
ScriptManager 控件。然后打电话
UpdatePanel
控件何时返回。

From the AsyncPostBackTrigger documentation:

Programmatically adding
AsyncPostBackTrigger controls is not
supported.
To programmatically
register a postback control, use the
RegisterAsyncPostBackControl method of
the ScriptManager control. Then call
the Update method of the UpdatePanel
control when the control posts back.

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