How to replace a asp.net control with a custom control

Source: Internet
Author: User

  This article mainly describes the way to replace a asp.net control with a custom control, which you need to refer to in the following

Function: You can replace a asp.net control with a custom control     pages tagmapping element (asp.net setup schema)     defines a collection of tag types that are mapped at compile time to other The tag type.     This element is a new element in the. NET Framework version 2.0.   Code as follows: <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:    Code as follows: <form id= "Form1" runat= "Server" >  <div>  <asp:label id= "LB1" runat= "Server" text= "LB" ></asp:Label>  </div>  </form>    Its generated HTML is as follows:  code 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>    in the pages node of the configuration file add     The code is as follows: <tagMapping>  <add tagtype= "System.Web.UI.WebControls.Label" mappedtagtype= cjq. Web.mylabel "/>  </tagMapping>    The code for the custom control is   code as follows: namespace CJQ. web  {  public class mylabel:system.web.ui.webcontrols.label  {  protected override void Rendercont Ents (System.Web.UI.HtmlTextWriter writer)   {  writer. Write ("Receive:");  base. RenderContents (writer); }   } }    Its generated HTML follows the following:  code: <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" > Receive:lb</span>  </div>  </form>   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.