ASP.NET 4.0 UpdatePanel and UserControl with PlaceHolder

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-20T03:21:49Z Indexed on 2010/04/20 3:23 UTC
Read the original article Hit count: 906

I don't know if this is ASP.NET 4.0 specific but I don't recall having this problem in previous versions.

I have very simple user control called "TestModal" that contains a PlaceHolder control which I use to instantiate a template in. When I put an UpdatePanel inside this UserControl on the page the updatepanel only does full postbacks and not partial postbacks. What gives?

USER CONTROL MARKUP:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestModal.ascx.cs" Inherits="MyProject.UserControls.TestModal" %>
<div id="<%= this.ClientID %>">
    <asp:PlaceHolder ID="plchContentTemplate" runat="server"></asp:PlaceHolder>
</div>

USER CONTROL CODE BEHIND:

public partial class TestModal : System.Web.UI.UserControl
{
    private ITemplate _contentTemplate;

    [TemplateInstance(TemplateInstance.Single)]
    [PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(TemplateControl))]
    public ITemplate ContentTemplate
    {
        get { return _contentTemplate; }
        set { _contentTemplate = value; }
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (_contentTemplate != null) _contentTemplate.InstantiateIn(plchContentTemplate);
    }
}

ASPX PAGE MARKUP:

<ajaxToolkit:ToolkitScriptManager ID="scriptManager" EnablePartialRendering="true" AllowCustomErrorsRedirect="true" CombineScripts="true" EnablePageMethods="true" ScriptMode="Release" AsyncPostBackTimeout="180" runat="server"></ajaxToolkit:ToolkitScriptManager>

<uc1:TestModal ID="testModal" ClientIDMode="Static" runat="server">
    <ContentTemplate>
        <asp:UpdatePanel ID="upAttachments" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">
            <ContentTemplate>
                <asp:LinkButton ID="lnkRemoveAttachment" runat="server"><img src="/images/icons/trashcan.png" style="border: none;" /></asp:LinkButton>
            </ContentTemplate>
        </asp:UpdatePanel>
    </ContentTemplate>
</uc1:TestModal>

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about updatepanel