Complete reusable UserControl library in .Net

Want a library of complete (including html rendering), re-usable user controls you can use across multiple projects? Read on…

I’ve recently worked on a project where the client wished to port an internal website (kiosk) to the web.

The project was built using lots of usercontrols (which was not ideal as this was the existing developers way to separate the business logic) and I wasn’t about to start copying these across the 2 projects.

I created an empty web site in the solution (not a web project) and copied across all the controls into the root.  After deleting the designer files as these aren’t used in a web site project, I published the site to a directory with the following options:

This would publish the site and all necessary dll’s to the specified folder.  Now, reference the web site assembly’s from the project you need them on and include a reference to them in the web.config:

<add tagPrefix=”uc” assembly=”Assembly.Name” namespace=”ASP”/>

Note: On inspection of the outputted dll in reflector an ASP namespace is created and this is the namespace you’ll need to use to get your user controls.  Also, I haven’t found a way to keep the control name classes the same, you’ll see they are now something like ‘controlname_ascx’ and this is what you’ll be using in the code <uc:controlname_ascx runat=”server” />.

To make things more annoying, the resulting dll’s that are published are random and contain a hash of the directory in which the website lives - this is by design and used for conflicts.  I use ILMerge to compile the assemblies into a single assembly with a pre-defined name so I don’t have to keep changing the references.

Following

  • the-absolute-funniest-posts
  • mikelernerphotography
  • funniest10k
  • attentionindustry
  • tastefullyoffensive
  • evangotlib
  • infoneer-pulse
  • merlin
  • poplipps
  • cavalier
  • redshooter
  • frezned
  • amyvernon
  • minimalistco
  • theclearlydope
  • deviantart
  • yagottabelieve
  • mashable
  • poptech
  • gregbabula
  • john
  • teaim
  • despicablealexis
  • purple-lightsaber
  • toptumbles
  • hellonewyork
  • nonprofit-design
  • plus5mace
  • wantful
  • pixel2html
  • adobegripes
  • kimjongillookingatthings
  • tuneage
  • mikehudack
  • sirmitchell
  • officialbeastieboys
  • wondertonic
  • jordanwaller
  • badassjs
  • iiiil0liiii
  • fuzzythinking
  • manxmidge
  • rosskempfolds
  • londonelek
  • bigpinots
  • hoveringartdirectors