Go to home page mail me! RSS Feed
FoxMetrics Web Analytics

Web.Config Pages Section

Thursday, March 22, 2007 12:07 AM

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" />

Your Comments.

  • # re: Web.Config Pages Section

    GravatarI want more number of configuration settings in this page

    Left by G.parthiban at 4/30/2007 2:39 PM
  • # re: Web.Config Pages Section

    Gravatarnice

    Left by george at 6/4/2008 3:23 PM
  • # re: Web.Config Pages Section

    GravatarIs there any over head if i put all my custom controls in web.config

    Left by Vaibhav at 9/11/2008 7:35 PM
  • # re: Web.Config Pages Section

    GravatarI did not run any sort of performance tests, neither have I noticed any difference with speed, so I'll say you can safely use it without any performance degrade.

    Left by Rydal Williams at 9/14/2008 10:46 AM
  • # re: Web.Config Pages Section

    GravatarGood One

    Left by sandilya at 2/4/2009 12:47 PM

Your Reply.

Comment Form.

Fields denoted with a "*" are required.

You may also like to leave your email or website.

 
Please add 7 and 8 and type the answer here:

Preview Your Comment.

 
Next entries »