Prev | Current Page 215 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

For this reason, you need to let
WebControl know what kind of HTML tag formulates your control??™s outer shell. You can do this
in one of two ways: by passing the tag via the HtmlTextWriterTag enumeration to the base
WebControl constructor or by setting either the TagKey or TagName property of WebControl. The
more common way is to use the base constructor:
public Label() : base(HtmlTextWriterTag.Span)
{
}
In the next section, we dive into WebControl-based control building and create a simple
Label control.
A Styled Label Control
Label controls are probably the simplest controls in the ASP.NET server control arsenal. They
have a single mission: to render a piece of content within a tag. To demonstrate the
styling powers of the WebControl class, we will build our own version of the Label control.
Listing 4-1 shows how easy this truly is.
Listing 4-1. The Label Control
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
CHAPTER 4 ?–  THE WEBCONTROL BASE C LASS AND CONTROL STYLES 135
namespace ControlsBook2Lib.Ch04
{
[ToolboxData("<{0}:label runat=server>"),
DefaultProperty("Text")]
public class Label : WebControl
{
public Label()
: base(HtmlTextWriterTag.


Pages:
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227