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
Views: 51392
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.

Absolutely Awesome Book on C# and .NET

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!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
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



Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by mudassar on Monday, September 3, 2007 4:56 AM
this is Excellent.........
it help me alot..........
Comment posted by syed on Thursday, February 28, 2008 11:15 AM
Thanx A lot...... EXCELLENT!!!!!!!!!!!
Comment posted by Thiyagarajan on Friday, February 29, 2008 9:52 AM
Really it's excellent
Comment posted by Karishma Goyal on Friday, June 10, 2011 12:40 AM
Simplicity of your answer is commendable.
With such a brief explaination & example, it can be understood very easily.
Thanks for sharing it..
$(this).siblings('.current').removeClass('current'); $(this).addClass('current'); $('.tabContent').children('.current').removeClass('current'); $('.tabContent').children().eq($(this).index()).addClass('current'); }); });