Method to replace an ES0en. net control with a custom control

  • 2020-12-13 18:56:52
  • OfStack

Features: You can replace an ES0en. net control with a custom control

tagMapping elements of pages (ASP.NET setup schema)

Defines a collection of 1 tag types that are remapped to other tag types at compile time.

This element is a new element in.NET Framework 2.0.
 
<pages> 
<tagMapping> 
<add 
tagType= 
"System.Web.UI.WebControls.WebParts.WebPartManager" 
mappedTagType= 
"Microsoft.Sharepoint.WebPartPartManager, 
MSPS.Web.dll, Version='2.0.0.0'" 
/> 
</tagMapping> 
</pages> 

Front-end code:
 
<form id="form1" runat="server"> 
<div> 
<asp:Label ID="lb1" runat="server" Text="lb"></asp:Label> 
</div> 
</form> 

The HTML generated is as follows:
 
<form name="form1" method="post" action="Default.aspx" id="form1"> 
<div> 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE1ODYxMzExNjlkZIRGtA8oGwNrNQd7V9ZkX3zxcLan" /> 
</div> 

<div> 
<span id="lb1">lb</span> 
</div> 
</form> 

Add to the pages node in the configuration file
 
<tagMapping> 
<add tagType="System.Web.UI.WebControls.Label" mappedTagType="CJQ.Web.MyLabel" /> 
</tagMapping> 

Where the code for the custom control is
 
namespace CJQ.Web 
{ 
public class MyLabel : System.Web.UI.WebControls.Label 
{ 
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer) 
{ 
writer.Write(" Reception: "); 
base.RenderContents(writer); 
} 

} 
} 

The HTML generated is as follows:
 
<form name="form1" method="post" action="Default.aspx" id="form1"> 
<div> 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE1ODYxMzExNjlkZIRGtA8oGwNrNQd7V9ZkX3zxcLan" /> 
</div> 

<div> 
<span id="lb1"> Reception: lb</span> 
</div> 
</form> 

Related articles: