System WebUIDesign WebControls ReadWrite ControlDesigner

Adds support for in-place editing, as in the Panel control. This support allows you to place other controls on top of a control in design time. The RequiredTextBoxDesigner parameterless constructor is provided so that the class can be created without requiring any parameters.

The bulk of the work of the designer is done in the GetDesignTimeHtml method. The method first gets an instance of the control. This instance can be used for retrieving or setting parameters. In this case, it's just there to show how you would obtain the current instance of the class. A StringWriter and an HtmlTextWriter are created (from the System.IO namespace). A new HyperLink object is created, and the placeholder link is rendered. The text of the hyperlink object is set to "RequiredTextBox Designer", but it could be any arbitrary HTML code.

Another option, which will result in the design-time appearance of a gray raised box similar to a button, is to use the CreatePlaceHolderDesignTimeHtml method, passing in a string parameter that will then be rendered on the gray box. Looking back again at Figure 6-7, two things about the Properties window are worth noting. First, the items in the Properties window are displayed in categories, and so the parameters I declared through the use of attributes as part of the Validator category are displayed together. Just as important, the ValidatorColor property is not just a text box in which you would enter names or numbers for colors but is instead a complete color picker, as shown in Figure 6-10.


R pni lirprfTpHl-RnH 1 Mufrmtnnk R sni lir t

Custom Web System)

I I LiahtGray I ! Gainsbom CD WhiteSmoke CD White I I RosyBrown ^M JndianRed [ I from M Firebrick CD UghtCorei ■I Maroon ^M DarkRed



Validator Color

Figure 6-10 : The color picker, made available to our RequiredTextBox custom control

The same behavior will occur with any type that has a complex property picker. Declare a property of the correct type, and the enhanced property picker becomes available with no additional programming required.

0 0

Post a comment