Can someone tell me how I can load a user control from within another user control.

I'm using MOSS 2007


I got the following code from the MDSN on line libray:

<%@ Page Language="C#" %>
<%@ Reference Control="~/Controls/Spinner.ascx" %>
<script runat="server">
private ASP.Spinner Spinner1
protected void Page_Load(object sender, EventArgs e)
  Spinner1 = (ASP.Spinner)LoadControl("~/Controls/Spinner.ascx");
protected void Button1_Click(object sender, EventArgs e)

<asp:PlaceHolder runat="server" ID="PlaceHolder1" />
<br />
<asp:Button ID="Button1" runat="server" Text="Click to Add User Control" OnClick="Button1_Click" />

basically you have to load the new control code behind and attach it in a place older so you have to set a PlaceHolder in the first control or something that can contains the Child-Control

This is the MSDN ref: http://msdn.microsoft.com/en-us/library/c0az2h86(v=vs.100).aspx

| improve this answer | |
  • no working thanks but no thank you – Mathematics May 9 '13 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.