Dynamically Load User Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two navigation user controls and based on a query string will load one
or the other.

On the page that will load the user control I cannot do the following

Dim uc As FlashNavigation (The name of the code behind class)
I also can't do CType(uc, FlashNavigation)

I get Type 'FlashNavigation' is not defined. How can I dynamically load a
user control then access it's properties and or methods?
 
Hi Nick,

Use Placeholder control to load usercontrol dynamically, i have placed the
code below.

///<summary>
///
///</summary>
protected System.Web.UI.WebControls.PlaceHolder Body;


/// <summary>
/// Call this to add a named control as the body of the page.
/// Return a ref to the control that has ben created.
/// </summary>
/// <param name="bodyname">The name of the user control to load</param>
public Control AddBody(string bodyname)
{
Control ctrl = LoadControl(bodyname);
Body.Controls.Add(ctrl);
return ctrl;
}
 
Back
Top