Brian's Blog

items I see across my tribes

Building Re-Usable ASP.Net User Controls

January 11
by briancarter 11. January 2009 20:30

Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005

Getting to a position where you have collateral and a repeatable process (that works), takes a great deal of effort.  I have a few clients that require ~70% of the same functionality.  The first step is to get your Re-Usable platform in place.  My choice is BE.N and user controls.  This allows me to have a consistent platform that I learn all the details (and pain points) to be effective in delivering solutions.  The controls allow for reuse and rapid deployment.  For rapid deployment, Scott Guthrie again, has a great article on the best practices.  Using fixed naming and single page assemblies allows you to deploy only the controls that change.  Go away you full deploy on every single update!

Building and Deploying the Web Project Library from the VS IDE 
To build and publish/deploy my web library solution within the Visual Studio IDE, I can go to the “Build” menu and select the “Publish Web Site” option.  This will bring up the “Publish Web Site” build dialog which provides me with the various deployment/compilation options on how to build the site:   For this walkthrough I am

going to use the default “updatable” option (meaning the HTML + Server control markup is preserved), and select to have individual assemblies created for my .ascx and .aspx files.  The reason for selecting the individual assembly option is because I want to be able to remove the compiled code for the root test pages and master templates that I am currently using to test my store-front library, and want to have the flexibility to update these assemblies on a more granular level in the future. 

When I click the “ok” button, VS 2005 will compile all three projects (myclasslibrary, mywebproject, mytestproject) and then deploy the classlibrary and webproject into the “BuildOutput” directory we defined earlier under our c:\sources\libraries\ecommerceUI\ directory.

Note that the .aspx/.ascx files will remain (because they still have .html/server control content defined within them), but all code-behind files are now gone – since they have been compiled into assemblies underneath the \bin directory.

Categories: Development


 Questions or Feedback, my contact information is located on my About page.


The opinions, thoughts, and comments made in these blog posts are solely my own (unless otherwise stated). They do not reflect the opinions, thoughts or practices of my employer, my universities, my family, or anyone else. Also, I retain the right to change my mind about anything I publish here without having to go back and edit posts that occurred in the past. 

These are my opinions, or just as likely, someone else's opinions that I leveraged for my own.