473,378 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
Nov 18 '05 #1
1 13601
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" <jo**@rb.com.auREMOVETOEMAIL> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
3
by: Guadala Harry | last post by:
I have this scenario: ASPX Page dynamically loads userControl1 - which in turn dynamically loads userControl2. UserControl2 contains a TextBox Web Server control. When a user clicks a button in...
1
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new...
0
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied...
3
by: voro.cibus | last post by:
I have been reading up on this all day, and I can't find the answer (or more likely, don't understand the answers I have found) to my problem. I have a table that stores the name of my ascx page....
14
by: Joe | last post by:
Hello All: I am trying to dynamically populate a web page with literal content and controls (textboxes and checkboxes (and eventually two buttons - the buttons do not appear in the code yet). I...
2
by: Ben Amada | last post by:
Hello, A partner is going to be creating some HTML files that I plan on converting to user controls (UC) and dynamically load at runtime. I'm guessing Visual Studio doesn't come with some...
1
by: =?Utf-8?B?SlA=?= | last post by:
I have a default.aspx page. Default.aspx has placeholders. ASCX user controls are loaded into these placeholders at Page_Load. Each user control has a MultiView, within that there are two views...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.