Dynamically Load User Control

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?
 
G

Guest

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top