The culprit
causing the implementation challenge is the design of the Style base class and how WebControl
interacts with it.
Both WebControl and the Style class have an implementation of the AddAttributesToRender()
method, as Figure 4-17 illustrates. The WebControl version does things such as add utility attributes
to the HTML start tag for the control for settings such as Enabled, AccessKey, ToolTip, and
TabIndex via the HtmlTextWriter AddAttribute() method. It also walks through the Attributes
collection of WebControl, adding those through HtmlTextWriter as well.
Figure 4-17. WebControl and Style AddAttributesToRender()
The Style class instance that is linked to the ControlStyle property is called by WebControl
to add its style properties through its version of AddAttributesToRender(). There is one caveat
with this call. It is executed only if the Style object signals that its internal state has been modified
via the return value of the Style IsEmpty property. In the base Style class, IsEmpty is declared
CHAPTER 4 ?– THE WEBCONTROL BASE C LASS AND CONTROL STYLES 173
as internal. Because we want our new version of IsEmpty to be called, we hide the base class
version by declaring our version of IsEmpty with the new modifier:
protected internal new bool IsEmpty
{
get
{ // Call base class version to get default behavior
return base.
Pages:
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268