views:

268

answers:

3

Is it possible to compile a web application project .ascx (user control) into a dll?

I want to do the following:

  1. Use the same control in multiple websites
  2. Embed css and .js as resources into the control
  3. Be able to update super easy. If the user control updates, I just want to update 1 .dll

I have successfully followed this article, http://msdn.microsoft.com/en-us/library/aa479318.aspx.

However, that uses web site projects, and I cannot embed js css as resources into web site projects.

Any ideas? Am I going about this wrong, should I change the approach?

+2  A: 

It is difcult to use user controls in this way due to the markup ascx file. If you want to create reusable control libraries your are much better off creating custom controls.

Ben Robinson
I'd add to that, if the user control isn't highly composite, then this is the least painful way to go. In fact I've refactored code so that my ascx files weren't composite controls just so they'd be easier to make into server controls, often these inherit from some built in ASP.NET control.
MatthewMartin
Creating a custom control isn't really an option in this case, I am getting the code from a third party, which I am trying to then embed into 3 different websites. I don't have control over how I get the code, and I don't want to re-write it into a custom control, especially as every update they give will have to be re-written.
cjburkha
Rather than trying to crowbar user controlls into a dll you can reference, you would be better off just using the source of the user controls in each web app and keeping them in sync using source control such as subversion's externals feature. http://justaddwater.dk/2007/10/23/setting-up-subversion-externals-with-tortoisesvn/
Ben Robinson
A: 

I had to do it once and I followed this article

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

It's based on the possibility of mounting a virtual file system on different places (an assembly, database, etc)

Claudio Redi
A: 

There are quite a few articles out there on how to do exactly that:

http://www.nathanblevins.com/Articles/Compile-a-Web-User-Control-into-a-DLL-.Net-c-.aspx

http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx

Josh
Both of those links deal with Web Site Projects, you cannot embed resources into a web site project as far as I can tell
cjburkha