Registering assembly and tagPrefix of controls in web.config

A couple of days ago I found a great way to register my assemblies with their own prefix. Normally you would do this kind of stuff using a page directive at the top of the page where you would want to use this control. Now if you want to use the Ajax Control toolkit for example, then you would register the assembly this way:

<%@ register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

What if you have 50 pages where you want to use this toolkit ? Then you would need to do this 50 times for every single page.

An easier way is to register the assembly and namespace in the web.config file of your project. In the configuration file look for the <system.web> tag. When you have found that look for this section:

<pages> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add tagPrefix="cc1" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/> </controls> </pages>

In the above code snippet I have already added the line for the Ajax Control Toolkit. When this is done the tagPrefix cc1 for the toolkit will be available in every page.

You can do this for any control you want, even your custom controls.


No comments yet. Be the first.

Leave a reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word