473,382 Members | 1,424 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,382 software developers and data experts.

Composite controls

Hi,

I am attemping to write a composite control but have so far not achieved the
results that I am looking for and would appreciate some advice.
By a composite control, i mean, a Web User control that has another web user
control passed to it as one of the arguments in the containing aspx page.

For example say I have a web page MyPage.aspx

Inside MyPage.aspx I have a user control "Control1.ascx"

I have another user control "Control2.ascx" that I would like to include in
Control1, I do not want to hard code "Control2.ascx" inside "Control1.ascx"
because in another page I might want to pass "Control3.ascx" as an argument
to "Control1.ascx"

My prolem is how to make a user control an arument to another control.
The best method I have come up with so far is to pass the path of user
"control2.ascx" to "Control1.ascx" as an argument of type string and then
use "Loadcontrol" to dynamically load the control, but this way seems messy
to me (as well as a little difficult to master..) so I was hoping for some
advice off anybody who had achieved a similar thing.

cheers

martin.

Nov 17 '05 #1
3 1620
"martin" <ma****************@yahoo.com> wrote in message
news:OH*************@TK2MSFTNGP11.phx.gbl...
Hi,

I am attemping to write a composite control but have so far not achieved the results that I am looking for and would appreciate some advice.
By a composite control, i mean, a Web User control that has another web user control passed to it as one of the arguments in the containing aspx page.

For example say I have a web page MyPage.aspx

Inside MyPage.aspx I have a user control "Control1.ascx"

I have another user control "Control2.ascx" that I would like to include in Control1, I do not want to hard code "Control2.ascx" inside "Control1.ascx" because in another page I might want to pass "Control3.ascx" as an argument to "Control1.ascx"

My prolem is how to make a user control an arument to another control.
The best method I have come up with so far is to pass the path of user
"control2.ascx" to "Control1.ascx" as an argument of type string and then
use "Loadcontrol" to dynamically load the control, but this way seems messy to me (as well as a little difficult to master..) so I was hoping for some
advice off anybody who had achieved a similar thing.


I don't really see any other way for you to do it. There are two ways to
instantiate an User Control. One is to put it on a page or other user
control, in which case it will appear within that page or user control,
which you don't want. The other way is to call LoadControl...

The only trick to it is that you have to remember to load Control2 on every
request, not just if (!Page.IsPostBack). Also, you'll have to have a
PlaceHolder inside of Control1 and you'll have to Add the loaded Control2 to
that PlaceHolder's Controls collection:

myPlaceHolder.Controls.Add(LoadControl(controlToLo ad));

--
John
Nov 17 '05 #2
John,

Thanks for the response.
However I am having trouble loading the usercontrol2 inside usercontrol1 if
I miss out the

<@reference control='UserControl2'> inside user control1.

I am kinda hoping that to dynamically include a control you don not have to
hard code a reference to it in the page.
else this sort of defeats the purpose of dynamically including it with
LoadControl(..).

I don't know if you can offer me any further advice on this issue or point
me to an article that may feature a similar thing.

cheers for the advice adding to the Placeholders controls collection, handy
there is no <form1 ..> in a user control.

cheers

martin.

"John Saunders" <john.saunders at surfcontrol.com> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
"martin" <ma****************@yahoo.com> wrote in message
news:OH*************@TK2MSFTNGP11.phx.gbl...
Hi,

I am attemping to write a composite control but have so far not achieved the
results that I am looking for and would appreciate some advice.
By a composite control, i mean, a Web User control that has another web

user
control passed to it as one of the arguments in the containing aspx page.
For example say I have a web page MyPage.aspx

Inside MyPage.aspx I have a user control "Control1.ascx"

I have another user control "Control2.ascx" that I would like to include

in
Control1, I do not want to hard code "Control2.ascx" inside

"Control1.ascx"
because in another page I might want to pass "Control3.ascx" as an

argument
to "Control1.ascx"

My prolem is how to make a user control an arument to another control.
The best method I have come up with so far is to pass the path of user
"control2.ascx" to "Control1.ascx" as an argument of type string and then use "Loadcontrol" to dynamically load the control, but this way seems

messy
to me (as well as a little difficult to master..) so I was hoping for some advice off anybody who had achieved a similar thing.


I don't really see any other way for you to do it. There are two ways to
instantiate an User Control. One is to put it on a page or other user
control, in which case it will appear within that page or user control,
which you don't want. The other way is to call LoadControl...

The only trick to it is that you have to remember to load Control2 on

every request, not just if (!Page.IsPostBack). Also, you'll have to have a
PlaceHolder inside of Control1 and you'll have to Add the loaded Control2 to that PlaceHolder's Controls collection:

myPlaceHolder.Controls.Add(LoadControl(controlToLo ad));

--
John

Nov 17 '05 #3
"martin" <ma****************@yahoo.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
John,

Thanks for the response.
However I am having trouble loading the usercontrol2 inside usercontrol1 if I miss out the

<@reference control='UserControl2'> inside user control1.


Martin, you're saying you're having trouble, but you don't say what the
trouble is, nor do you show us the code which is having the trouble.
--
John
Nov 17 '05 #4

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

Similar topics

0
by: Phil S. | last post by:
I'm having dreadful trouble putting a simple composite control into the DataGrid cell, so I'm hoping someone might have stumbled across this problem before and have some advice. My composite...
5
by: KJ | last post by:
This is kind of hard to explain but I have a The controls are created with CreateChildControls(). Now let say I click a button and an error occurs in the control. If I throw it up it goes back...
1
by: sleigh | last post by:
Hello, I'm building a web application that will build a dynamic form based upon questions in a database. This form will have several different sections that consist of a panel containing one to...
10
by: dx | last post by:
I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and Components book. It's starting to shine some light on control development but there is something about composite...
2
by: Harry | last post by:
Hello, I have a composite WebControl that I'm dynamically instantiating at runtime using Reflection. When I create a new instance of my control I immediately iterate through it's child control...
0
by: AndrewF | last post by:
Hi there. I am royally stuck with this so any help would be greatly appreciated. Basically I have a set of classes that create composite controls for the user. One of these is an upload object...
4
by: Mark Olbert | last post by:
This involves a family of related, databound ASPNET2 composite controls. I've managed to arrange things so that the composite controls restore themselves from ViewState on postback after they're...
3
by: Beavis | last post by:
I hate to repost a message, but I am still at the same point where I was when I originally posted, and hopefully someone else will see this one... Ok, so I have gone off and documented the...
6
by: shapper | last post by:
Hello, I am working in a class library with various custom controls. In which cases should a control inherit Control, WebControl and CompositeControl classes? And when should a custom...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.