Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Passing Parameters to User Controls that are Dynamically Loaded in Placeholders

 
Thread Tools Search this Thread
Old 05-26-2004, 12:51 AM   #1
Default Passing Parameters to User Controls that are Dynamically Loaded in Placeholders


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.AppSett ings["virtualPath"]
+ "editButton.ascx");
UserControl c2 = (UserControl)
LoadControl(System.Configuration.ConfigurationSett ings.AppSettings["virtualP
ath"]
+ "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.

Thanks, Josh




Josh
  Reply With Quote
Old 05-26-2004, 01:42 AM   #2
Jeffrey Palermo [MCP]
 
Posts: n/a
Default Re: Passing Parameters to User Controls that are Dynamically Loaded in Placeholders
Josh,
There are plenty of ways to do this.
1. The user control has access to the Form and Querystring collections.
2. The user control has access to the HttpContext.Current.Items collection.
3. You can make a base class for your dynamic user controls and make public
properties. Then you can declare the dynamic control as MyUserControl
instead of UserControl and set the properties after LoadControl().

A dynamically loaded user control is still a user control, so getting
information to it is the same.

For a practical example of a dynamically-loaded user control, you can check
out my EZWeb workspace on GotDotNet.com. I implement a "Master Pages"
feature with v1.1 by make templates using UserControls and dynamically
loading them. Then code in the user controls gets information (or the
parameters you speak of): http://workspaces.gotdotnet.com/ezweb.

Regards,
Jeffrey Palermo


"Josh" <> wrote in message
news:%...
> 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.AppSett ings["virtualPath"]
> + "editButton.ascx");
> UserControl c2 = (UserControl)
>

LoadControl(System.Configuration.ConfigurationSett ings.AppSettings["virtualP
> ath"]
> + "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.
>
> Thanks, Josh
>
>





Jeffrey Palermo [MCP]
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46