Search code examples
c#asp.netuser-controlsascx

How do I use an asp.net user control in another user control?


I have a user control (gallery.ascx) and I want to use the photo.ascx control in the gallery control. I've added this register at the top of gallery.ascx, but it still can't find photo:

<%@ Register TagPrefix="ssctrl" TagName="photo" Src="controls/photo.ascx" %>

Any ideas?


Solution

  • In case anyone is wondering, the Register is correct, my photo user control tag was just not formed properly. I did have it as:

    <ssctrl:photo ID="Photo" Key="<%# Eval("PageTemplatePK") %>" runat="server" />
    

    and the Key property needed to use single quotes instead of double quotes because it was using an Eval expression:

    <ssctrl:photo ID="Photo" Key='<%# Eval("PageTemplatePK") %>' runat="server" />
    

    After that, it worked.