To replace a ASP.net control with a custom control method _ Practical Tips

Source: Internet
Author: User
Function: You can replace a asp.net control with a custom control

tagmapping element of pages (asp.net setup schema)

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

This element is a new element in the. NET Framework version 2.0.
Copy Code 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:
Copy 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:
Copy Code code as follows:

<form name= "Form1" method= "post" action= "default.aspx" Id= "Form1" >
<div>
<input type= "hidden" name= "__viewstate" id= "__viewstate"/ Wepdwullte1odyxmzexnjlkzirgta8ogwnrnqd7v9zkx3zxclan "/>
</div>

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

Join in the Pages node of the configuration file
Copy Code code as follows:

<tagMapping>
<add tagtype= "System.Web.UI.WebControls.Label" mappedtagtype= "CJQ". Web.mylabel "/>
</tagMapping>

Where the code for the custom control is
Copy Code code as follows:

Namespace CJQ. Web
{
public class MyLabel:System.Web.UI.WebControls.Label
{
protected override void RenderContents (System.Web.UI.HtmlTextWriter writer)
{
Writer. Write ("Receive:");
Base. RenderContents (writer);
}

}
}

Its generated HTML is as follows:
Copy Code code as follows:

<form name= "Form1" method= "post" action= "default.aspx" Id= "Form1" > br><div>
<input type= "hidden name=" __viewstate "id=" __viewstate "value="/ Wepdwullte1odyxmzexnjlkzirgta8ogwnrnqd7v9zkx3zxclan "/>
</div>

<div>
<span id=" L B1 "> Receive:lb</span>
</div>
</form>
Related Article

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.