How to globally register user and custom controls in ASP.NET 2.0
Posted by: Suprotim Agarwal ,
on 8/8/2007,
in
Category ASP.NET
Abstract: Abstract : In this short article, we will learn how to globally register user and custom controls in your web.config file. This saves us from repeatedly declaring the Register directive on every page where the control is being used.
How to globally register user and custom controls in ASP.NET 2.0
In previous versions of ASP.NET, if you wanted to import and use any user or custom control, you needed to add a page directive <%@ Register %> in that .aspx page. Shown below is an example of the register directive for a user control.
<%@ Register TagPrefix="uc" TagName="table" Src="table.ascx" %>
<body>
<form id="form1" runat="server">
<div>
<uc:table ID="Table1" runat="server" />
</div>
</form>
</body>
In ASP.NET 2.0, managing controls has become easier. Instead of declaring them on every page, you can declare them only once in your web.config file and use them in your entire project.
<configuration>
<system.web>
<pages>
<controls>
<addtagPrefix="uc"tagName="table"src="table.ascx" />
</controls >
</pages >
</system.web>
</configuration>
Once you have registered this control in your web.config, you can use this control on any page without explicitly adding a register directive on the page.
<body>
<form id="form1" runat="server">
<div>
<uc:table ID="Table1" runat="server" />
</div>
</form>
</body>
While using this control, you will also notice the intellisense support which saves us from remembering the syntax for using the control.
Well that’s it. It’s that easy. Thanks to the book MVP: Hacks and Tips book from Wrox which mentioned this tip.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!
Was this article worth reading? Share it with fellow developers too. Thanks!
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of
DotNetCurry,
DNC Magazine for Developers,
SQLServerCurry and
DevCurry. He has also authored a couple of books
51 Recipes using jQuery with ASP.NET Controls and
The Absolutely Awesome jQuery CookBook.
Suprotim received the prestigious Microsoft MVP award for 17 consecutive years, until he resigned from the program in 2025. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that offers Digital Marketing and Branding services to businesses, both in a start-up and enterprise environment.
Get in touch with him on Twitter @suprotimagarwal or at LinkedIn