2

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...

David Masters
  • 8,069
  • 2
  • 44
  • 75

2 Answers2

1

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.

Chris Moutray
  • 18,029
  • 7
  • 45
  • 66
  • 1
    Yep. Nice one. I put it in the pre render because of issues with using the data pager with the list view: (http://stackoverflow.com/questions/234289/listview-with-datapager-not-working) but it really doesn't make sense to do the databind in the pre render. – David Masters Jan 10 '14 at 10:11
0

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>
delirek
  • 70
  • 1
  • 6