Using tag mapping to change the mapping of user control through out the application

Hi,

Lets say you are working in a fairly large asp.net application. You have about 200 web pages. Now because of situation (or clients request) you want to change all the textbox or button control to some server control or user control.

This can be very very tedious JOB if you are using Asp.net 1.X. But if you are using Asp.net 2.0 or Asp.net 3.0, wait, there is a very easy way to get this done.

Tag mapping seems to be made for these kinds of situations. In asp.net 2.0 we can map tags in web.config. With the help of tag mapping we can remap the tag types to other tag types at compile time.

The remapping will make all the original tag to use the new mapping for all the pages and user control in the asp.net application coming in scope of the configuration file.

Hence for our situation we can map all the button tags to a tag in our site like this.

<system.web>
  <pages>
    <tagMapping>

      <add tagType="System.Web.UI.WebControls.Button"

           mappedTagType="Vikram.MyButton"/>
    </tagMapping>
</pages>

After we add the following line of code in the web.config file all the button control will be mapped to the button at Vikram.MyButton.

The tag mapping is configurable at machine.config, Root level web.config, Application level web.config or virtual or physical directory level web.config file.

This also means that we can add mapping for a particular control for all the pages and controls in a folder. This can be super useful when you want to change some controls (lets say a button) mapping for all the pages in a folder.

Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2009 Vikram Lakhotia