ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
What is ASP?
VBScript Classes: Part 1 of N
Migrating to ASP.NET

Use RecordSet.Filter
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

How to Register a Control for Application-Wide Use

Most users know that if you want to use a custom server or user control on an ASP.NET page, you need to register it first. This is normally done via a <%@ Register %> directive at the top of the page. You're probably familiar with the syntax:

  <%@ Register TagPrefix="asp101" TagName="SampleControl" Src="Controls/SampCtrl.ascx" %>

This method works well, but can be somewhat cumbersome if you'll be using the control on a number of pages. If you'll be using the same control throughout your application, you can actually register it in your web.config file. This alleviates the need to register the control on each and every page and makes management much easier if you ever decide to move the control's source file.

The web.config section we'll be using is: configuration -> system.web -> pages -> controls

  <?xml version="1.0"?>
          <add tagPrefix="asp101" tagName="SampleControl" src="~/Controls/SampCtrl.ascx" />

Once you register a control here, you can then use it on any page within your application without the need to include the <%@ Register %> directive at the top of the page. This works on ASP.NET 2.0 and later and trust me... once you start using it you won't look back.

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers