ASP.NET 2 projects to share same files - asp.net

Well as the title says i have 2 web projects that have the same css files, master page and some resource files, how could i share those? atm i have 2 copies of them...

Solution 1: bind them into separate assemblies in share it across your projects.
Reference:
Building Re-Usable ASP.NET User Control and Page Libraries with Visual Studio 2005
How to embed resources in ASP.NET 2.0 assemblies

Here is an article that describes how to share pages and user controls between applications : HOW TO: Share ASP.NET Pages and User Controls Between Applications by Using Visual Basic .NET. It's solution depends on separate virtual directory that holds the shared files.
And in this article Scott Guthrie describes how to build reusable web assemblies. It's solution depends on making separate assembly by shared files.

In the second project choose "Add existing file", select the file, click on the arrow on the add button and select "add as link".

Related

web.config.CLR4 file

What is the use of web.config.CLR4 file in asp.net web application ? To be specific i came across it while examining tools developed by infragistics i.e in netadvantage product which provides tools like grid view, tab, tree view for developing web applications. As well please help me with step wise solution to develop a tool from the scratch in asp.net using c#.
In order to successfully deploy your ASP.NET project to IIS you need web.config appropriate for the target CLR, thus there are different web.config files for CLR2 CLR35 and CLR4.

Best practice for integrating a silverlight control in a Asp.Net Solution

I need some advice regarding the handling of a Silverlight control that I need to integrate into an existing Website, coded with Asp.Net.
I'm using SVN, Visual Studio 2010, Framework 4.0. I need to create a simple silverlight control and I need to have it embedded in one of my asp.net pages.
My question is basically, what is the best practice on where to put this Silverlight control?
1) Creating a new project for my Silverlight control and then refer to it through an external tools within my website? (importing only the .xap?)
+ Reuse
- Seems lot of extra work for a small control
2) Create a new project withing my website solution, compile it next to my website and create a post build event to copy the .xap generated into a ClientBin folders in my website?
- Lack of reusability
+ Easy to make small modifications in my Silverlight component.
3) Another solution I don't know yet??
Thanks for your advices
Do not worry about number of projects. Reuse is far more important (we have solutions with over 100 projects).
Create a new Silverlight application, then add a Silverlight relationship between the website and your new Silverlight application:
Right-click on your website project and select Properties.
Choose the Silverlight Applications tab on the left side
Press Add...
Leave Use an existing Silverlight project in the solution checked and select the project you want to add from the Project dropdown.
Leave Add a test page that references the control checked if you want a separate test page for your application.
Press Add and you are done.
The website will now build your Silverlight application and include the output Xap file in its ClientBin folder.
If you check "add a test page", that will give you sample HTML/ASPX pages and the JavaScript you need to run the Silverlight component anywhere in your ASP.Net app.

How to create redistributable user control in DLL form with embedded images, javascripts, style sheets?

I've developed a most reusable ASP.Net WebUserControl for our company's web applications. I'm now going to make it as a redistributable DLL according to this msdn topic. Since the WebUserControl comes with some JavaScript(s), CSS(s) as well as images. I'm asking how can I bundle them all together to form a single DLL?
Our development environment is Visual Studio 2008, .Net Framework 3.5
Please kindly advise!
Thanks!
William
You could bundle the non source code parts in a resource file and reference them through there in your ASP.NET code. You could add to the default resource file (.resx) or add your own..
I haven't actually tried this but I think you could embed the user controls, JS files, etc into the output assembly of your reusable library project. Basically in the Properties dialog you'd set the "Build Action" to "Embedded Resource" for those files instead of "Content".
Then the consuming application would implement and register a VirtualPathProvider to tell ASP.NET to look for user controls inside the assembly.
Here's a similar question dealing with loading MVC Views from a DLL, same idea: Using VirtualPathProvider to load ASP.NET MVC views from DLLs
And this: http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/

ASP.NET Sharing a user control/web page logic with multiple web applications

I have a web application, which has a user control and web page logic to be used on multiple web applications. The reason I want to do this is that I want the other web applications to reference this one since the html/css of their web pages varies.
First of all I wanted to ask if this is possible since it is a web application and not a class library.
Secondly if it is possible how do I refrence the web page logic to the htmls of the other web applications?
How about adding the Web User Control to a Class Library and referencing that Class Library from the website ?
Here are instructions by Haacked on how to add a User Control to a Class Library: http://haacked.com/archive/2006/02/07/AddingWebUserControlToAClassLibraryInVS.NET2005.aspx
Also here is a post by Guthrie about Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005 and I think it's worth a look.
[Update]
I found a better tutorial on Creating and Using User Control Libraries. I think that this article is more concise than the other one by Guthrie (also this one is also by Guthrie)
Compile and deploy your asp.net website which will produce one assembly per code-behind.
Pick the assembly of the code-behind class you want to re-use and drop it into the \bin folder of your 2nd web-app in which you want to reuse it.
Now this assembly will have a partial class which you can merge with the code-behind of an existing web-page. Just ensure the naming hierarchy are matching.

Is it possible to add a web user control to a class library?

I'm looking at building some web user controls with an eye toward re-use, but I can't seem to add a Web User Control in my class library in VS2008. Is there a way to work around this problem, or is there a better approach to creating reusable controls?
You can create either Web User Controls or Web Custom Controls that encapsulate the functionality you need. The main difference between the two controls lies in ease of creation vs. ease of use at design time.
You should maybe consider creating a Web Custom Control library. There is a walkthrough for creating a web custom control using the Web Control Library template.
According to the MSDN article "Recommendations for Web User Controls vs. Web Custom Controls" these are the differences between the two types of controls:
Web user controls are easy to make,
but they can be less convenient to use
in advanced scenarios. You develop Web
user controls almost exactly the same
way that you develop Web Forms pages.
Like Web Forms, user controls can be
created in the visual designer, they
can be written with code separated
from the HTML, and they can handle
execution events.
However, because Web
user controls are compiled dynamically
at run time they cannot be added to
the Toolbox, and they are represented
by a simple placeholder glyph when
added to a page. This makes Web user
controls harder to use if you are
accustomed to full Visual Studio .NET
design-time support, including the
Properties window and Design view
previews.
Also, the only way to share
the user control between applications
is to put a separate copy in each
application, which takes more
maintenance if you make changes to the
control.
Web custom controls are compiled code,
which makes them easier to use but
more difficult to create; Web custom
controls must be authored in code.
Once you have created the control,
however, you can add it to the Toolbox
and display it in a visual designer
with full Properties window support
and all the other design-time features
of ASP.NET server controls.
In addition, you can install a single
copy of the Web custom control in the
global assembly cache and share it
between applications, which makes
maintenance easier. For more
information see global assembly cache.
Follow the following steps (from this post by Phil Haacked):
Close VS.NET 2005.
Open the directory C**:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\CSharp** (assuming a default installation of VS.NET).
Open the CSharpItems.vsdir file in Notepad. Select the text and copy it to the clipboard.
Now open up the file C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjectItems\CSharpItems.vsdir and paste the contents of the clipboard underneath the existing text.
Now copy the contents of C:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\CSharp (excluding CSharpItems.vsdir) into the folder C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjectItems.
Now “Web User Control” should be an option when you select Add | New Item.
Reference: http://haacked.com/archive/2006/02/07/addingwebusercontroltoaclasslibraryinvs.net2005.aspx
As platte's link mentions, if you're going for reuse then Web User Controls aren't very good. The ascx file has to be manually copied to every project you want to use them in, or you have to hack your way around that.
It's better to use System.Web.UI.WebControls.WebControl which is what you get when you add an "ASP.NET Server Control". These are designed for reuse. If one of the existing framework controls fits the bill for the most part and you just need to extend the functionality of it, then add an "ASP.NET Server Control" and change it to inherit from Panel or Menu or whatever.
If you're still determined to get reusable Web User Controls to work, then this article by The Gu should set you on the right path.
There is a project template called "ASP.NET Server Control" that I assume you can use...
--larsw
You can do anything in a class library.
Add reference to System.Web
Create your new Control class that inherits
from WebControl or HtmlControl or
whatever.
That's it. You now have a reusable control for ASP.NET.
You could do some special things like add attributes to your class and properties, but they are really not needed.
[DefaultProperty("Text")]
[Category("...")]
[DefaultValue("")]
You could using virtual path providers but you you should consider whether it really is worth your wile. Consider this codeproject article on the subject.

Resources