Wednesday, March 28, 2012

Multiple UpdatePanels updated by single trigger -- bug or feature?

Hi, not sure if this has been discussed before but..

I'm running April CTP, and I have two UpdatePanels on my page. UpdatePanel1 includes a navbar with various LinkButtons, and the other UpdatePanel2 contains a GridView. I've added a ControlEventTrigger to UpdatePanel2 for the click event of the LinkButtons in UpdatePanel1. UpdatePanel1 has no triggers (I plan on adding triggers at a later time). The issue is, when I click a LinkButton from UpdatePanel1, it updates both UpdatePanels! I would like it to only update UpdatePanel2 as I thought it should, but maybe I am just not understanding the way UpdatePanels work.

I'm thinking the fact that UpdatePanel2 is using a Control Event from UpdatePanel1, this might be the cause of these problems. When I moved the LinkButtons out of UpdatePanel2, UpdatePanel1 was no longer updated. I've included the source code for the two UpdatePanels:

<atlas:UpdatePanel runat="server" ID="UpdatePanel1" Mode="Conditional"> <ContentTemplate> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td><asp:LinkButton CssClass="navlink_selected" ID="homeLinkT" runat="server" OnClick="link_Click" CommandName="home" CommandArgument="1" >home</asp:LinkButton> <asp:LinkButton CssClass="navlink_unselected" ID="aboutLinkT" runat="server" OnClick="link_Click" CommandName="about" CommandArgument="2" >about</asp:LinkButton> <asp:LinkButton CssClass="navlink_unselected" ID="resumeLinkT" runat="server" OnClick="link_Click" CommandName="resume" CommandArgument="3" >resume</asp:LinkButton> <asp:LinkButton CssClass="navlink_unselected" ID="projectsLinkT" runat="server" OnClick="link_Click" CommandName="projects" CommandArgument="4" >projects</asp:LinkButton> <asp:LinkButton CssClass="navlink_unselected" ID="forumLinkT" runat="server" OnClick="link_Click" CommandName="forum" CommandArgument="5" >forum</asp:LinkButton> <asp:LinkButton CssClass="navlink_unselected" ID="contactLinkT" runat="server" OnClick="link_Click" CommandName="contact" CommandArgument="6" >contact</asp:LinkButton> </td> <td style="width:80px"> <atlas:UpdateProgress ID="up1" runat="server"> <ProgressTemplate> <asp:Image ID="Image2" runat="server" ImageUrl="~/images/Hourglass_iconsm.gif"/> </ProgressTemplate> </atlas:UpdateProgress> </td> </tr> </table> </ContentTemplate> </atlas:UpdatePanel> <atlas:UpdatePanel runat="server" ID="UpdatePanel2" Mode="Conditional"> <ContentTemplate> <asp:HiddenField ID="page_id" runat="server" Value="1" /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="page_id" DataSourceID="ObjectDataSource1" ShowHeader="False" GridLines="None" AutoGenerateEditButton="false" > <Columns> <asp:TemplateField> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Height="100%" Text='<%# Bind("page_content")%>' TextMode="MultiLine" Width="600px" Rows="10"></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("page_content")%>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="page_id" HeaderText="page_id" ReadOnly="True" SortExpression="page_id" Visible="False" /> </Columns> </asp:GridView> </ContentTemplate> <Triggers> <atlas:ControlEventTrigger ControlID="homeLinkT" EventName="Click" /> <atlas:ControlEventTrigger ControlID="aboutLinkT" EventName="Click" /> <atlas:ControlEventTrigger ControlID="resumeLinkT" EventName="Click" /> <atlas:ControlEventTrigger ControlID="projectsLinkT" EventName="Click" /> <atlas:ControlEventTrigger ControlID="forumLinkT" EventName="Click" /> <atlas:ControlEventTrigger ControlID="contactLinkT" EventName="Click" /> </Triggers> </atlas:UpdatePanel>

Anyone have any ideas?

Thanks,

Matt

This is not a bug, but the intended result.

Clicking a server control that causes a postback (i.e. a link button or a normal button) when that server control is contained within the ContentTemplate of an UpdatePanel will cause that UpdatePanel to update even if it is not explicitly defined as a trigger. UpdatePanel1 is updating for this reason and UpdatePanel2 is updating because the control is defined as a triggering event.

Ah, thanks for the clarification Joel!

Matt


So is there a way for getting around this? If I have a menu of links and I want some to be loaded into one updatepanel and some into another. Is this even do-able?

Thanks.

No comments:

Post a Comment