Friday, August 13, 2010

Tag Mapping in ASP.NET

Tag Mapping in ASP.NET

 Tag mapping allows you to swap compatible controls at compile time on every page in your web application. A useful example is if you have a ASP.NET control, such as a TextBox, and you want to replace it with a customized control that is derived from TextBox. Instead of editing every web form and replacing the built in TextBox with your custom version, you can have ASP.NET in effect do it for you by modifying web.config:



    <clear />

    <add tagType="System.Web.UI.WebControls.TextBox" mappedTagType="TextBox"/>



When you run your application, ASP.NET will replace every instance of TextBox with CustomTextBox, which is derived from TextBox:

public class CustomTextBox : TextBox


    public CustomTextBox()



    // Control the multline length here 


In this way you can write the custom logic that controls the multiline length ie its not controled on version 2.0
The only thing that we need to remember is that when we do a tag mapping in the web.config file we need to derive form the WebControls ie there will always be a base class for the tag mapping .
Internally how it works is that when the creates/manulpulates the control,it actually check inside the web.config and picks the mapped controls


Post a Comment