Adding Design-Time Support to Your Extender ControlThe introduction of the Extender Wizard in Visual Studio 2008 has enhanced the design-time experience with regard to working with extender controls, and this section explains how to add design-time features of your own to give your controls that professional feel that users have become accustomed to.Default Design-Time ExperienceThe ImageRotatorDesigner class shown in Listing 11.2 provides everything we need to get a basic design-time experience for our extender control. The ExenderControlBaseDesigner<T> that it inherits from makes it possible for the properties of our extender control to show up in the Properties window while the design-time focus is on the image control we are extending. Figure 11.4 shows the RotationInterval and ImageList properties that appear in the Properties window while the image control has focus in the designer. This default feature addresses one issue, which is being able to work with the ImageRotator properties in an integrated way, but still does not address the issue of data entry for the properties themselves and how that experience can be enhanced.Figure 11.4 Extender properties on the image control Adding Designers and Editors to PropertiesIn this section, we look at how to extend the design-time behavior of our ImageRotator ImageList property. The ImageList property that we worked with in Chapter 5 was rudimentary and prone to errors as a user entered in the values. In this version of the extender, we want to extend the functionality to support design-time editing and HTML source editing.The road to these modi.cations requires a few steps as we add the functionality: Add attributes to the class. Add attributes to the property. Add editors to assist in assigning values. Create a type converter to support serialization. Add Attributes to the ClassMost users expect when adding multiple entries to a control to be able to add them in the body of the HTML element. This is the experience we have when adding web service references or script references to the Script Manager and one we want to have in our control.The ParseChildren attribute enables us to add multiple entries inside our ImageRotator HTML tag and treat those entries as a single property assignment. By setting the ChildrenAsProperties property to true and the DefaultProperty to ImageList, as in Listing 11.6, we are effectively telling the designer that we want to have all the items contained in the body of our ImageRotator tag parsed and assigned to the ImageList property. The HTMLfragment in Listing 11.7 shows what this looks like when the HTML editor is opened and the ImageRotator tag has entries.Listing 11.6 ParseChildren Attribute Assignment[ParseChildren(true, "ImageList")] public class ImageRotatorExtender : ExtenderControlBase{ }Listing 11.7 ImageList Assignment in HTML<asp:Image ID="BannerImage" runat="server" ImageUrl="~/images/1.jpg" /><cc2:ImageRotatorExtender ID="BannerImage_ImageRotatorExtender"runat="server" Enabled="True" TargetControlID="BannerImage"><cc2:ImageUrl Url="~/images/2.jpg" /><cc2:ImageUrl Url="~/images/3.jpg" /><cc2:ImageUrl Url="~/images/4.jpg" /></cc2:ImageRotatorExtender>NOTE ASP.NET Server Control Designer ReferencesThe addition of designer features to your extenders requires some knowledge of how designers work. MSDN has some great information about this at http://msdn2.microsoft.com/en-us/library/aa719973%28VS.71%29.asp that covers adding design-time support to ASP.NET server controls.
Adding Design-Time Support to Your Extender ControlThe introduction of the Extender Wizard in Visual Studio 2008 has enhanced the design-time experience with regard to working with extender controls, and this section explains how to add design-time features of your own to give your controls that professional feel that users have become accustomed to.Default Design-Time ExperienceThe ImageRotatorDesigner class shown in Listing 11.2 provides everything we need to get a basic design-time experience for our extender control. The ExenderControlBaseDesigner<T> that it inherits from makes it possible for the properties of our extender control to show up in the Properties window while the design-time focus is on the image control we are extending. Figure 11.4 shows the RotationInterval and ImageList properties that appear in the Properties window while the image control has focus in the designer. This default feature addresses one issue, which is being able to work with the ImageRotator properties in an integrated way, but still does not address the issue of data entry for the properties themselves and how that experience can be enhanced.Figure 11.4 Extender properties on the image control
Adding Designers and Editors to PropertiesIn this section, we look at how to extend the design-time behavior of our ImageRotator ImageList property. The ImageList property that we worked with in Chapter 5 was rudimentary and prone to errors as a user entered in the values. In this version of the extender, we want to extend the functionality to support design-time editing and HTML source editing.The road to these modi.cations requires a few steps as we add the functionality:
Add Attributes to the ClassMost users expect when adding multiple entries to a control to be able to add them in the body of the HTML element. This is the experience we have when adding web service references or script references to the Script Manager and one we want to have in our control.The ParseChildren attribute enables us to add multiple entries inside our ImageRotator HTML tag and treat those entries as a single property assignment. By setting the ChildrenAsProperties property to true and the DefaultProperty to ImageList, as in Listing 11.6, we are effectively telling the designer that we want to have all the items contained in the body of our ImageRotator tag parsed and assigned to the ImageList property. The HTMLfragment in Listing 11.7 shows what this looks like when the HTML editor is opened and the ImageRotator tag has entries.Listing 11.6 ParseChildren Attribute Assignment[ParseChildren(true, "ImageList")]
public class ImageRotatorExtender : ExtenderControlBase{
}Listing 11.7 ImageList Assignment in HTML<asp:Image ID="BannerImage" runat="server" ImageUrl="~/images/1.jpg" /><cc2:ImageRotatorExtender ID="BannerImage_ImageRotatorExtender"runat="server" Enabled="True" TargetControlID="BannerImage"><cc2:ImageUrl Url="~/images/2.jpg" /><cc2:ImageUrl Url="~/images/3.jpg" /><cc2:ImageUrl Url="~/images/4.jpg" /></cc2:ImageRotatorExtender>NOTE ASP.NET Server Control Designer ReferencesThe addition of designer features to your extenders requires some knowledge of how designers work. MSDN has some great information about this at http://msdn2.microsoft.com/en-us/library/aa719973%28VS.71%29.asp that covers adding design-time support to ASP.NET server controls.