Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help me with loading my usercontrol into a PlaceHolder

Status
Not open for further replies.

BlueBlade

Technical User
Joined
Mar 2, 2007
Messages
15
Location
US
Hi, using VB.NET, I am trying to load a UserControl into a PlaceHolder dynamically. In the WebForm I added the following directive:

<%@ Reference Control="../UserControls/SquareRoot.ascx"%>

In PageLoad I have this piece of code:

Dim uc As SquareRoot
Page.LoadControl("../UserControls/SquareRoot.ascx")
PlaceHolder1.Controls.Add(uc)

Here is my error message:

System.ArgumentNullException: Value cannot be null. Parameter name: child


Ultimately I want to load the control when my user click on a button but I thought I would try it in the PageLoad routine first.

Please help,


 
you must assign [tt]child[/tt] a value. Your posted code doesn't use the parameter [tt]child[/tt] so we can't help without more code.

also, since your loading the user control in the code behind you shouldn't need to reference it in the aspx.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Well, I'm not sure. Here is an example of one I'm currently using. I put this in the OnInit():

Code:
[blue]override protected void[/blue] OnInit(EventArgs e)
{
   InitializeComponent();
   [blue]base[/blue].OnInit(e);
   placeHolder.Controls.Clear();
   [blue]string[/blue] control = [red]"~/controls/UserInfo.ascx"[/red];
   placeHolder.Controls.Add(Page.LoadControl(control));
}

You shouldn't have to reference it on the .aspx page either. Also, make sure the path to the user control is correct ;-). Though I'm pretty sure you can, I'm not positive that you can use "../etc" in the value for the path.

Let me know if that helps at all.

Ron Wheeler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top