It would be cool if I can specify my custom controls in my web.config file and reference them by a unique tag names - I said to myself and bam! One of my favorite sections of the web.config file is the Pages section and thats because not only does it allow me to specify the default theme accross the site but I can also specify controls that are used in the application and visual studio will create intellisense on the fly that will allow me to use those entries via the cusom tag names that I specified. It doesn't get any better!

Prior to this new addition to the web.config file, one has to reference the library/custom control somewhere above in the page and then create a reference to one of the controls which leads to cumbersome code.

Ok, so let say we have a "controls" folder that holds all of our custom we controls and we want to use the web.config pages section to make it very easy to reference these controls. Note: these controls could be located in any folder, I just like to keep my stuff neat. The pages section goes within the "System.Web" section. Sample section:

 

    <pages theme="General">
      <controls>
        <add tagName="footer" tagPrefix="web" src="~/controls/footer.ascx"/>
        <add tagName="login" tagPrefix="web" src="~/controls/login.ascx"/>
        <add tagName="message" tagPrefix="web" src="~/controls/message.ascx"/>
        <add tagName="blogpost" tagPrefix="web" src="~/controls/blogpost.ascx"/>
      </controls>
    </pages>

 

To reference any of these controls in the web page, simply use the tagName. Example:

 

<web:blogpost ID="blogpost" runat="server" />

 

Note the "theme" attribute in the pages element. That simply sets the default theme for my website to the "General" theme, therefore, I don't have to specify themes on every single page.

Oh! If your controls are located in a library use the following syntax instead.

 

<add assembly ="Rydal.Web.UI" namespace ="Rydal.Web.UI.WebControls" tagPrefix="raw" />