You don't have to register web controls and user controls on every page!

One of the coolest things I learnt lately thanks to Dino Esposito’s excellent Atlas talk that I went to in Nice was that you can register your user controls and web controls in one place in the web.config file rather than at the top of every page.

You just need to add a <controls> tag to the <pages> tag in the web.config and add an entry for each web control or user control you want to use:

  1. <system .web>
  2.  …
  3.  <pages>
  4.    <controls>
  5.      <!– user controls –>
  6.      <add tagPrefix="usercontrol"
  7.        tagName="mycontrol"
  8.        src="~/Resources/UserControls/MyControl.ascx">
  9.  
  10.      <!– custom controls –>
  11.      </add><add tagPrefix="webcontrol"
  12.        assembly="MyWebControls"
  13.        namespace="MySite.WebUI.WebControls">
  14.    </add></controls>
  15.  </pages>
  16.  …
  17. </system>
Posted on 01 May 06 by Helen Emerson (last updated on 01 May 06).
Filed under ASP.NET