Search code examples
.netasp.netweb-controlsascx

Sharing ASCX-controls between different web applications


Is it possible to share web controls (.ASCX-files) between different web applications?

The files in question are part of another web project. I tried to edit the web.config to reference the ascx files but I got syntax errors, it tells me that Iam not allowed to use ".." in this path.

<pages>
   <controls>
      <add tagPrefix="my" tagName="IntegerInput" src="~/../MyCommonProject/controls/basic/IntegerInput.ascx" />

The basic problem I want to solve with that is that we have two applications which have lots of functionality in common, exspecially web controls.

So in short, we want to pull out all common functionality of these two projects in a separate project so we have no duplicate code in development, but the two projects should be able to get deployed separately as completely different applications, each getting their own copy of these controls.

How can we solve this?


Solution

  • I found two solutions for this problem:

    • Create a project which contains ascx'es and code. The source files of this project are shared with (i.e. xcopies to) other projects using the ascx'es. (blog)

    • Create a library for your User Controls, add existing ascx's and code-behind. Reference this library in the web projects. Drawback: You use design-time functionality, meaning: you don't see the ascx in Design Mode. (blog)

    The third solution, as suggested by @Forgotten Semicolon, would be to convert to server controls. This method also improves designer performance.