开发者

Sharing ASCX-controls between different web applications

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

T开发者_运维问答he 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?


You must convert the user control to a custom server control.

MSDN has an article here.


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.


There's another potential solution:

Keep the controls in a single directory in one web site you decide is the 'main' one; then create a virtual directory in the other site that points to the same physical directory.

This can really only work for the ascx files, not their code-behinds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜