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

Austin picture Austin · Oct 30, 2008 · Viewed 7.3k times · Source

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?

Answer

Austin picture Austin · Oct 30, 2008

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.