Reusing ascx web controls 11. April 2007 Comment (2) After developing and testing some ascx web controls in the past I was woundering why I have to copy them over to a new web project today instead of just referencing them. When you write a normal windows application and then want to reuse some library parts in another project (or if you just want to structurize your app a little bit better) you would obviously use a dll library for the job to share functionality.Not that easy with web controls. My first thought was just to copy the .ascx and .ascx.cs files over to a new dll project and start compiling. After adding the missing images and scripts the following thing happend:Well, the code does compile on a website, but in a dll project it will not build the ascx code for you and merge the controls defined there with your .cs file. If you do not define controls or do any visual stuff you can probably just use WebControls instead of UserControls, but you still have to implement the Render method yourself and you just do not have any design support. More information about creating server controls can be found here.While that solution is probably the cleanest one and has the advantage of hidding the source code and make it easy to just drag and drop controls on your page, it is the hardest to develop. And I already have my .ascx controls working, I just want them in another project without copying them over again and again.I searched for a while on the web for some solutions, see below for all the links. The best solution for me was the one from ScottGu, which just uses a normal website and then uses a post build copy to get all the files into your current website project. The controls dummy website can then be used all over the place, you just have to add the copy command to each website that should use your controls. This solution might not be the best, so if you have more complex problems, check out the links below.No reason to repeat all the stuff ScottGu has already written, check out his great article here or here.BTW: I use this just for simpler web controls or when I have something that needs to be duplicated on some pages. For Ajax controls on the other hand I got a project similar to the AjaxControlToolkit, but there you live without design time editors anyway.Links: Turning an ascx user control into a redistributable custom control from David Ebbo's ASP.NET blog5 step tutorial on building redistributable custom controls. Pretty good article, but the solution is too complex for me.Reusing Web User Controls accross applications by Adrian Hara's blogOverview about 3 different approaches and some useful notes.Using MSBuild and ILMerge to Package User Controls For Reuse from K. Scott Allen's blogA more complete, but also complexer, solution.ASP.NET: Reusing Web User Controls and Forms by CMS WireUsing virtual paths, looks very messy to me. Btw: Why are they using .php for their blog and talk about asp?WYSIWYG For Custom Web Controls on CodeProject.net by Alex SoldatovNice article on how to use .ascx files and converting them to a custom controls library.MSDN Information about creating server controls.ScottGu's article on Creating and Using User Control LibrariesThis was the easiest and most useful way to reuse my controls for me.This is the same article on his blog.