Thursday, March 29, 2012

sharing usercontrols across projects

Is it practical?
I have a site we've been working on where a lot of the objects on the page
are usercontrols...the header, the footer, navigation, etc.
I need to make a stand-alone mini-site that should not be connected to the
larger project, as it will be maintained by a different group by hand.
So, I was just going to copy over a few of the controls and place them in
here. Of course, that's easy, but not ideal, as now I have duplicates of the
exact same control. Is it possible to reference a control outside of your
own project?
-DarrelDarrel,
If you want to share controls between projects and not duplicate the code,
then you need to create a Custom Server Control library. You will not have
the luxury of having a .ascx file to define your HTML in, thus the
complexity rating of the task goes up. But, if you are like me after you
get over the learning curve then you start to favor custom controls over
user controls. You will have to implement either the Render method or the
CreatChildControls method. Render() method is used when you just would like
to utilize the HtmlTextWriter class and CreateChildControls is used when
creating a composite control.
The other thing you end up having to make when you do a custom control
library is create Designer classes for each of your controls so you can see
your controls in a certain way while view the web form in the designer.
Here is a nice index page of information that you will need to help you
along with this task.
http://msdn.microsoft.com/library/d...sercontrols.asp
HTH
-Chris
~
http://weblogs.austinspad.com/caustin
"darrel" <notreal@.hotmail.com> wrote in message
news:%23cWXGMSwEHA.3084@.TK2MSFTNGP10.phx.gbl...
> Is it practical?
> I have a site we've been working on where a lot of the objects on the page
> are usercontrols...the header, the footer, navigation, etc.
> I need to make a stand-alone mini-site that should not be connected to the
> larger project, as it will be maintained by a different group by hand.
> So, I was just going to copy over a few of the controls and place them in
> here. Of course, that's easy, but not ideal, as now I have duplicates of
the
> exact same control. Is it possible to reference a control outside of your
> own project?
> -Darrel
>
User controls weren't really designed to be shared between projects. For
advanced functionality such as that you should create custom controls.
Here's more info:
http://msdn.microsoft.com/library/d...WebControls.asp
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"darrel" <notreal@.hotmail.com> wrote in message
news:%23cWXGMSwEHA.3084@.TK2MSFTNGP10.phx.gbl...
> Is it practical?
> I have a site we've been working on where a lot of the objects on the page
> are usercontrols...the header, the footer, navigation, etc.
> I need to make a stand-alone mini-site that should not be connected to the
> larger project, as it will be maintained by a different group by hand.
> So, I was just going to copy over a few of the controls and place them in
> here. Of course, that's easy, but not ideal, as now I have duplicates of
> the
> exact same control. Is it possible to reference a control outside of your
> own project?
> -Darrel
>
> Here is a nice index page of information that you will need to help you
> along with this task.
>
http://msdn.microsoft.com/library/d...sercontrols.asp
Thanks, Chris!
-Darrel

0 comments:

Post a Comment