EasyHostingASP.NET | Best and cheap ASP.NET Hosting. Lets say you are working in a fairly large asp.net application. 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 , there is a very easy way to get this done using tagMapping.
Best and Cheap ASP.NET Core 1.0 Hosting in India Click Here !
it’s a way to turn all instances of a type into another type at compile time. In human language it means that it can turn all e.g. System.Web.UI.WebControls.Textbox (in our example ) instances in the entire website into another control.That is so cool that I had to do a little example. I’ve created a very simple control that inherits from a TextBox and overrides the Text property so that it HTML encodes the text. I placed it in the App_Code folder and called it SafeTextBox.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// /// Summary description for SafeTextBox /// public class SafeTextBox : System.Web.UI.WebControls.TextBox { public override string Text { get { return base.Text; } set { base.Text = System.Web.HttpUtility.HtmlEncode(value); } } } |
Then I needed to hook the tag mapping up in the web.config to convert all the text boxes into SafeTextBox instances. It simply converts all TextBox instances on the entire site. Here is what’s needed in the web.config:
1 | <pages> <tagMapping> <add tagType="System.Web.UI.WebControls.TextBox" mappedTagType="SafeTextBox"/> </tagMapping> </pages> |
After we add the following line of code in the web.config file all the TextBox control will be mapped to the TextBox.
- ASPHostPortal vs Site5 – Best Windows ASP.NET Hosting Comparison - September 29, 2017
- Best , Cheap Umbraco 7.7.1 Hosting Recommendation - September 28, 2017
- ASP.NET Web Forms Connection Resiliency and Command Interception - September 27, 2017