Create new account I forgot my password    

How to globally register user and custom controls in ASP.NET 2.0
Rating: 13 user(s) have rated this article Average rating: 4.5
Posted by: Suprotim Agarwal, on 8/8/2007, in category "ASP.NET 2.0 & 3.5"
Views: this article has been read 19846 times
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.









Page copy protected against web site content infringement by Copyscape


How would you rate this article?

User Feedback
Comment posted by mudassar on Monday, September 03, 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

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel

NEWSLETTER