2
votes

Basically I have this situation

Page > Update Panel > User Control > List View > User Control (Within item template) > Update Panel

When I click on a button within the inner most update panel, I want the content of the update panel to update. This isn't happening. However, the click handler is being hit fine asynchronously. The update panel just doesn't want to update.

Code - I've created a simple test web app that replicates the problem, and shared it on my google drive: UpdatePanelInListViewTest.zip, but here's the markup:

Page:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="ajaxParent" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <uc1:ListUserControl ID="ListUserControl1" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>

List User Control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ListUserControl.ascx.cs" Inherits="UpdatePanelInListViewTest.ListUserControl" %>
<%@ Register src="MiniWidget.ascx" tagname="MiniWidget" tagprefix="uc1" %>
<asp:ListView ID="lstTest" runat="server">
    <ItemTemplate>
        Item
        <uc1:MiniWidget ID="MiniWidget1" runat="server" />
    </ItemTemplate>
</asp:ListView>

Mini Widget User Control

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MiniWidget.ascx.cs" Inherits="UpdatePanelInListViewTest.MiniWidget" %>
<asp:UpdatePanel ID="ajaxWidget" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:LinkButton ID="lnkTest" runat="server" onclick="lnkTest_Click">Test</asp:LinkButton>
        <asp:Label ID="lblTest" runat="server" Text=""></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

I've tried different permutations of this; i.e. having the button outside the panel and adding a trigger etc but I just cannot get it to update.

It appears that because the user control is within an item template of the parent list view it causes the update panel to not update for some reason...

2
Is UpdateMode="Conditional" on your top-level UpdatePanel ? Can you try changing it to "Always" ? - sh1rts
I've tried both. No success - David Masters
Btw I don't want the parent to update, so it should be set to conditional. - David Masters
Can you post the markup for your page and for the parent usercontrol, so I can try this myself and see what's happening ? - sh1rts
drive.google.com/file/d/0B4skfAO1E7ZvWnZaLVE2eUpFRk0/… Does this link work? I've created a test project with the problem replicated. When you click the link within the items it should update a label - David Masters

2 Answers

1
votes

The problem is to do with when you call the databind method within ListUserControl.

Moving lstTest.DataBind(); so that it executes within the Page_Load rather than the Page_PreRender fixes the issue for your simple test web app.

0
votes

have u tried:

    <asp:UpdatePanel ID="ajaxPanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
 <Triggers>
      <asp:AsyncPostBackTrigger ControlID="btnTest" />
 </Triggers>
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Button ID="btnTest" runat="server" Text="Test" onclick="btnTest_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>