Search code examples
.netprojects-and-solutionsascxweb-user-controls

sharing web user controls across projects


I've done this using a regular .cs file that just extends System.Web.UI.UserControl and then included the assembly of the project that contains the control into other projects. I've also created .ascx files in one project then copied all ascx files from a specified folder in the properties->Build Events->Pre-build event.

Now what I want to do is a combination of those two: I want to be able to use ascx files that I build in one project, in all of my other projects but I want to include them just using assembly references rather than having to copy them to my "secondary" projects as that seems a ghetto way to accomplish what I want to do. It works yes, but it's not very elegant.

Can anyone let me know if this even possible, and if so, what the best way to approach this is?


Solution

  • Fundamentally, user controls were never meant to be shared across projects. If you want to create controls that are reusable across projects, you should create server controls that are compiled into a DLL which can simply be referenced by other projects.

    Developing Custom ASP.NET Server Controls