Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Composite controls

Reply
Thread Tools

Composite controls

 
 
martin
Guest
Posts: n/a
 
      11-01-2003
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.



 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      11-02-2003
"martin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
martin
Guest
Posts: n/a
 
      11-02-2003
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:(E-Mail Removed)...
> "martin" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
>
>



 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      11-04-2003
"martin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Composite vs non composite Controls Mike ASP .Net Web Controls 4 03-11-2005 05:47 AM
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
composite controls... Microsoft Press: Dev ASP.NET Server Controls dx ASP .Net 10 04-10-2004 11:33 PM
Composite control with dynamic composite controls sleigh ASP .Net 1 02-12-2004 06:24 PM



Advertisments