advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
Tip of the Day
Average Rating: 0.8/5 | Rate this item | 169 users have rated this item.
Expertise: Intermediate
Language: .NET
December 7, 2009
Globally Register User and Custom Controls in ASP.NET

In previous versions of ASP.NET, to import and use user or custom controls on a page, you needed to add a page directive (<%@ Register %>) in the .aspx code for that page.

Fortunately, ASP.NET 2.0 introduced a shortcut that makes managing the controls much easier. Rather than declaring them on every page, you can declare them once, in your web.config file, and then use them in your entire project.

Register your controls in web.config as shown below. The example assumes that there is a user control named table.ascx in the project:

<configuration>
<system.web>
<pages>
<controls>
<addtagPrefix="uc" tagName="table" src="table.ascx" />
<!-- Add other user/custom control references here -->
</controls >
</pages >
</system.web>
</configuration>

You can now use the table.ascx user control on any page—without explicitly adding a Register directive on the page. Here's a short example:

<body>
<form id="form1" runat="server">
<div>
<uc:table ID="Table1" runat="server" />
</div>
</form>
</body>
Deepak Choudhari
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
Please rate this item (5=best)
 1  2  3  4  5
advertisement
advertisement