views:

722

answers:

3

I have a ASP.Net web application that I want to use as a reusable user control library in other web applications.

One solution for this problem is to use what Scott Guthrie has described here:

http://weblogs.asp.net/scottgu/archive/2005/08/28/423888.aspx

that is to copy ascx/aspx files (without their code-behind) in the web applications which use the control library.

I actually see another solution: to embed the ascx/aspx in the User control library and then use a custom virtual path provider to get them.

Does anybody know which solution is the best ?

From the deployment point-of-view, the virtual path provider seems to be better. However the 'ascx/aspx copy' solution is easier to implement (no need to create a custom virtual path provider).

+1  A: 

I really do not like Scott's solution. I believe it is ungly and creates overhead that is not necessary. I have also seen something similar in action and it just didn't work for me.

I too had the same requirement as you describe and I used the virtual path provider option. This way I could reuse all my user controls between web applications easily and without work arounds.

The virtual path provider has a couple of issues though:

  • If your ascx file has any server tags (in javascript or any other place for that matter) that cause an issue you will get a run time error that is not that helpful.
  • You have to rebuild your application every time you do a change to the ascx's mark up or to Javascript that exists on the file it self in order to see the results. That can be a real pain if you are trying to change the design of an existing control.

I have used the solution as described in this article and it worked very well:

http://www.codeproject.com/KB/user-controls/EmbeddedUserControl.aspx

I hope that helps...

tolism7
A: 

I ran into this same situation a few weeks ago and I could not make Scott's solution work. I instead used Custom Server Controls and put those in their own Class Library.

Mike C.
A: 

I really don't think its a good idea to use user controls that way. If you need them in a separate library, you should convert them to server controls.

Gabriel McAdams