Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-06
7
Medium Priority
?
381 Views
Last Modified: 2008-03-10
Hi.

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 ASP.net, 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.

0
Comment
Question by:Bconner26
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Accepted Solution

by:
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.

Regards,

Aeros

0
 
LVL 15

Assisted Solution

by:Thogek
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).
0
 

Author Comment

by:Bconner26
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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 15

Expert Comment

by:Thogek
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., http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwalkthroughdevelopingsimplewebformscontrol.asp
0
 
LVL 17

Expert Comment

by:AerosSaga
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
 Get
   If Not Label1 Is Nothing Then Return Label1.TexT
 End Get
End Property

Regards,

Aeros
0
 
LVL 15

Expert Comment

by:Thogek
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:
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconwebusercontrolsvscustomwebcontrols.asp
0
 

Author Comment

by:Bconner26
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

972 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