Trying to load a control into a control from another control

Exactly as the subject states, I'm trying to load a control into another control from a control loaded into a page, I keep getting this error from the code I have below.  I've also tried the findcontrol but it keeps coming up null.

(67): 'System.Web.UI.UserControl' denotes a 'class' where a 'variable' was expected

UserControl ut = ((webcontrols.BrowseItems)UserControl).LoadControl("BrowseItems");
((webcontrols.BrowseItems)UserControl).pnl_browse_main.Controls.Add(ut);

0
thespace
1/19/2005 3:36:24 PM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 1 Replies
👁️‍🗨️ 1551 Views


This is how we Load User controls into a content place holder.


try
{
UserControl ctl;
ctl = (UserControl)LoadControl(PagePath.ReturnPagePath(Request.QueryString["CurrentPage"]));
this.contentPlaceholder.Controls.Add(ctl);
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.Write("Unable to load " + (string)Session["CurrentPage"] + " control");
}

You need to replace the whole ctl call with the UserControl object the you created. When you Response.Write your execption on a load fail. change the output to whatever you would like to display.
By looking at your naming scheme it looks like you just want to fill a Panel. For this we usually make a Panel on the page and goto the solution explorer then drag and drop the usercontrol we wish to display into the panel. If you are not wanting to change this dynamically later in your solution the drag and drop is the easiest way to go.


It's not a bug, it's a feature.



Brian Parker
CEO, Cofounder
NeoTekSystems
Phone:(864)770-0473
Fax:(864)770-0476
www.neoteksystems.com
bparker@neoteksystems.com
0
brianparker
1/19/2005 4:12:32 PM
Reply: