Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How do you sharing web forms and code classes across multiple projects in Visual Studio?

Posted on 2004-08-06
Medium Priority
Last Modified: 2008-03-10

I am developing multiple websites using ASP.NET in Visual Studio (using Visual Basic).
I have many clients that require a similar web site.  The core structure is the same, as well as most of the code.  However, the websites do have differences, such as image files, CSS files, a vb class that I use to store connection information.  To put it another way, there is a basic core that is shared, with particular variations in a limited number of files.

So here's the problem.  When I change the code of a core component, I want ALL websites to benefit from that enhancement.  So far I only have two websites in, but I am converting other sites over from ASP and I may end up with as much as 10-12 websites to maintain.  I would like to not have to maintain 12 separate sites, but leverage the fact that most of the site is shared.

I have tried looking into a single solution with multiple projects, but it seems that a project is pretty much a stand-alone application, and that project files can't be used for other projects (I think).

I have also looked into deployment projects that could specify which files are part of a particular application.  But there are two disadvantages that I think would exist here:
1. I don't host my own sites and I don't have administrator priveleges on the web server (documentation states that I need this for web deployment setup).
2. I'm not sure how I would be able to develop and view one particular website without deploying it.

Any help that would get me going in the right direction would be appreciated.

Question by:Bconner26
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 17

Accepted Solution

AerosSaga earned 750 total points
ID: 11736690
Classes from projectX are available if you reference the projectX in projectY.  That is I have a site that requires Payment gateway processing, and shipping calculation.  So what I do is I have a moduler solution called shipping for example.  I just copy the entire solution into the new project, and add a reference to that project.  Then any public classes that I need from the shipping solution are available to me in my site by initiating a new instance of the class and then passing the paramaters to the class for the manipulation.  If you have any further questions, just ask as I know that was probably not the most concise explination.



LVL 15

Assisted Solution

Thogek earned 750 total points
ID: 11737105
To put it another way (but basically the same as what AerosSaga is saying)....
Files/classes/etc for a given project can be used by any other projects within the same solution -- with the exception of ASCX and ASPX files.  The using project just has to add the used project as a project reference, and be sure to get the namespaces correct (if they're different) when referencing classes from the used project.  So you should be able to abstract most/all of your common logic into classes and components that can be shared by all Web projects and placing those items into their own project, and then include that project into each of the Web application project's solutions (or just load 'em all into one solution; whichever's easier for you to manage).

Author Comment

ID: 11738394
Thanks for the ideas concerning classes.  This will be useful to share that across projects.

However, the majority of the websites I deal with are made up of ASPX files.  This is what most of them share (both the HTML part and the code behind them).  Is there any way to share those files across projects in the way I described in the question?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 15

Expert Comment

ID: 11739582
ASPX files?  I don't think so.

You may want to look into creating your own custom controls (not ASCXs) to encapsulate the reusable HTML about which you are concerned.  This loses the ability to work on the control's own HTML structure with a nice design surface for these controls (as the HTML would typically then be generated by code in a Render method), but gains the ability to be reusable across multiple projects.  (Much like the built-in ASP.NET controls such as DropDownLists, etc.)

See, e.g.,
LVL 17

Expert Comment

ID: 11740046
Correct me if I'm wrong Thogek; by creating .ascx controls with the content one can gain access to the controls like so:

Dim x1 As myCustomControl = DirectCast(Me.FindControl("ReportMenu1"), myCustomControl)
                myPageLabel.text = x.MyCustomControl.Label.Text

Public ReadOnly Property GetMyLabelText() As String
   If Not Label1 Is Nothing Then Return Label1.TexT
 End Get
End Property


LVL 15

Expert Comment

ID: 11740102
That gains you programmatic access to the control once it's on the page, yes.  That's a little different from being able to reuse ASCX files across projects.

Some other references:

Author Comment

ID: 11852163
Thanks for your help.  I'll split the points.  I was able to create a project that contained classes to share across projects.  So the more code I put in classes, the more can be shared.  I'm not quite at the level of custom controls, but I'll try that sometime.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question