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

Posted on 2004-08-06
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 250 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 250 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?
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

624 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