Asp. NET Create server Control Sample code

Source: Internet
Author: User
It's easy to create your own ASP.net server control. When you create a simple custom control, all you have to do is define a class derived from System.Web.UI.Control and override its Render method. The Render method takes parameters of the System.Web.UI.HtmlTextWriter type. The HTML that the control sends to the client is passed to the HtmlTextWriter Write method as a string parameter.
For example:
Server control code (simple display String): Simple.cs:

Here is Simple.cs:
Imports System
Imports system.web
Imports System.Web.UI
Namespace Simplecontrolsamples
public class Simplecsharp
{

protected override void Render (HtmlTextWriter Output)
{
Response.Write ("<H2> Welcome to asp.net source Download professional station <H2>");
}
}

Referencing file simple.aspx:

Here is simple.aspx:
<%@ Register tagprefix= "simplecontrolsamples" namespace= "Simplecontrolsamples" Simplecontrolsamplescsharp "%>
<body>
<form method= "POST" action= "simple.aspx" runat=server>
<simplecontrolsamples:simplecsharp id= "MyControl" runat=server/>
</form>
</body>



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.