all groups > asp.net building controls > may 2004 >
You're in the

asp.net building controls

group:

Passing Parameters to User Controls that are Dynamically Loaded in Placeholders



Passing Parameters to User Controls that are Dynamically Loaded in Placeholders josh NO[at]SPAM rb.com.au
5/25/2004 4:43:52 PM
asp.net building controls: Hi Guys,

I have been having a big problem with trying to pass parameters into a
user control when the user control is dynamically loaded into a
placholder. I am developing in c#. I have get and set methods on the
user control "editButton.ascx" which work fine.

How do i pass parameter into the user controls "c1", "c2" ?

Here is a bit of my code that is calling the user control from the
aspx page.
public void setupTemplate(string PID)
{
//load control into a placeholder
UserControl c1 = (UserControl) LoadControl
System.Configuration.ConfigurationSettings.AppSettings["virtualPath"]
+ "editButton.ascx");
UserControl c2 = (UserControl)
LoadControl(System.Configuration.ConfigurationSettings.AppSettings["virtualPath"]
+ "editButton.ascx");

//PLACEHOLDER 1
PlaceHolder phPlaceHolder =
(PlaceHolder)this.FindControl("Form1").FindControl("PlaceHolder1");
phPlaceHolder.Controls.Clear();
phPlaceHolder.Controls.Add(c1);
//PLACEHOLDER 2
PlaceHolder phPlaceHolder2 =
(PlaceHolder)this.FindControl("Form1").FindControl("PlaceHolder2");
phPlaceHolder2.Controls.Clear();
phPlaceHolder2.Controls.Add(c2);
}

Any help would be greatly appreciated.

Re: Passing Parameters to User Controls that are Dynamically Loaded in Placeholders samgeribo NO[at]SPAM yahoo.com
5/25/2004 11:41:09 PM
Hi,

Just cast it to the appropriate type, ie. instead of (UserControl) put
(editButton) or whatever you called the extended class in
editButton.ascx.

-Sam

[quoted text, click to view]
AddThis Social Bookmark Button