Inline Server Tags Re-Eavluated on Partial Postback from UpdatePanel?

262 views Asked by At

I have a web application where I'm trying to use a user control with an UpdatePanel so that the control can be updated on the web page using a partial postback.

I have defined the ScriptManager in the Master page for the site. It is place outside of the ContentPlaceHolder but inside the form tag for the body as represented below:

<head>     
   <asp:ContentPlaceHolder ID="HeadContent" runat="server" />
</head>
<body>
   <form runat="server" class="form-horizontal">
      <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />
      <asp:ContentPlaceHolder ID="MainContent" runat="server" />
</body>

In the content page I have some HTML that using inline server tags to bind to data and a user control that contains the UpdatePanel as represented below:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="ClientDetail.aspx.cs" Inherits="ClientDetail" Async="true" %>
<%@ Register src="../controls/ListSelectionControl.ascx" tagname="ListSelectionControl" tagprefix="lsc" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
   <link href="<%= ResolveClientUrl("~/css/clientdetail.css") %>" rel="stylesheet" type="text/css" />
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
   <div>
      Client: <%= this.CurrentClient.Id %> - <%= this.CurrentClient.Name %>
   </div>
   <div>
      <lsc:ListSelectionControl ID="ItemsListSelectionControl" runat="server" />
   </div>
</asp:Content>

The UpdatePanel in the user control includes a couple of listboxes and buttons to move items from one list to another. The buttons are registered as AsyncPostbackTriggers and are marked as CauseValidation="false" to prevent the validators in other parts of the page from firing. The UpdatePanel is represented below:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ListSelectionControl.ascx.cs" Inherits="ListSelectionControl" %>

<div>
   <asp:UpdatePanel ID="udpListSelection" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="false">
      <Triggers>
         <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
         <asp:AsyncPostBackTrigger ControlID="btnRemove" EventName="Click" />
         <asp:AsyncPostBackTrigger ControlID="btnAddAll" EventName="Click" />
         <asp:AsyncPostBackTrigger ControlID="btnRemoveAll" EventName="Click" />
      </Triggers>
      <ContentTemplate>
         <div>
            <asp:ListBox ID="lstAvailableItems" runat="server" SelectionMode="Multiple" Rows="15" />
         </div>
         <div>
            <asp:Button ID="btnAdd" CausesValidation="false" runat="server" OnClick="AddItems" Text="Add >" />
            <asp:Button ID="btnRemove" CausesValidation="false" runat="server" OnClick="RemoveItems" Text="< Remove" />
            <asp:Button ID="btnAddAll" CausesValidation="false" runat="server" OnClick="AddAllItems" Text="Add All >" />
            <asp:Button ID="btnRemoveAll" CausesValidation="false" runat="server" OnClick="RemoveAllItems" Text="< Remove All" />
         </div>
         <div>
            <asp:ListBox ID="lstSelectedItems" runat="server" SelectionMode="Multiple" Rows="15" />
         </div>
      </ContentTemplate>
   </asp:UpdatePanel>
</div>

The code behind on the buttons simply manages the exchange of the data between the list boxes and I don't believe it's relevant here.

The problem that I'm having is that when the partial postback occurs (breakpointing the code in the Master page and analysing the IsInAsyncPostback property determines that it is a partial postback) the page is processing the inline ASP server code and failing because the CurrentClient object is not being re-populated. I'm looking to understand why this is happening and why the partial postback is not simply updating my UpdatePanel as I expected?

Thank you for your assistance.

Richard

1

There are 1 answers

0
TheCatWhisperer On

I regretfully have to inform you of some bad news... update panels have a lot of issues inside of UserControls... hopefully you can find some sort of work around.