Creating a Custom Control of Our Own

As usual, we'll start with the obligatory Hello World example. In this case we're going to create a custom control that does nothing more than output the text “Hello World”. We will see shortly how we can do this by inheriting from existing controls, such as the Label, but for now, we will simply inherit from the base class Control. The source code for our control is listed in Listing 12.1.

Listing 12.1. A C# Hello World Control, HelloWorld.cs
 namespace ASPNETByExample { public class HelloWorld : System.Web.UI.Control { protected override void Render(System.Web.UI.HtmlTextWriter htwOutput) { htwOutput.Write("Hello ...

Get ASP.NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.