Odds, Ends, and the WebControl Base Class

All Web controls implement a long list of properties that enable them to be customized in a variety of ways. Some of those properties are defined in the control classes themselves; others are inherited from the WebControl base class. For example, all Web controls have properties named Width and Height because both of these properties are members of WebControl.

Not all WebControl properties are as ordinary as Width and Height. Take, for example, WebControl鈥檚 CssClass property. I鈥檓 frequently asked whether Web controls support cascading style sheets (CSS). The answer? Yes they do, thanks to the CssClass property that they inherit from WebControl. The following example defines a CSS class named Input and uses it to modify a TextBox control to display text in red 10-point Verdana type:

聽聽聽聽聽聽<asp:TextBox聽CssClass="Input" RunAt="server" />

ToolTip is another property that Web controls inherit from WebControl. Want to display a tooltip window when the cursor hovers over a control? Then include a ToolTip attribute in the control tag, like this:

<asp:TextBox聽ToolTip="Type聽your聽name聽here" RunAt="server" />

There鈥檚 virtually no end to the customizations you can perform when you have a firm grasp of all the properties and events that ASP.NET鈥檚 Web controls expose. And when the built-in Web controls don鈥檛 do what you want, you can always build controls of your own鈥攚hich is precisely what the next two chapters are all about.