ASP.NET: Registration of Controls in Web.Config

3. April 2006

In ASP.NET 1.x controls had to be registered in each page they were used. New since ASP.NET 2.0, controls can be registered in the web.config file. Visual Studio 2005 supports full intellisense when editing .aspx pages. This feature allows commonly used controls to be more easily used through out your application.

Web.Config


<system.web>
    <pages>
        <controls>
            <add tagPrefix="mycontrol" src="~/Controls/Header.ascx" tagName="header"/>
            <add tagPrefix="mycontrol" src="~/Controls/Footer.ascx" tagName="footer"/>
        </controls>
    </pages>
</system.web>

Use the control in an .aspx page


<mycontrol:header id="Header" runat="server" />

asp.net



Comments

Raul Macias
Raul Macias
4/11/2006 4:14:00 AM #
What are the advantage/disadvantage of this new way of registering user controls (.ASCX)? Better performance?
Also, can custom server controls be registered in the same way?
1/20/2007 10:09:00 PM #
The main advatage is that you can specify the same tagPrefix for each control. Doing that allows you to easily copy controls from one page to the other.
Comments are closed