The Custom Designer Class is where you will control what gets displayed in Design View for the Web Control. You will leverage Microsoft's System.Web.UI.Design.ControlDesigner. All you are going to do is override the two methods GetDesignTimeHtml and GetEmptyDesignTimeHtml.
4.1. System.Design Assembly In order to use the System.Web.UI.Design.ControlDesigner Microsoft class, you will need to add a reference to the assembly to the project.
4.1.1. Add Reference
In the Solution Explorer, Right Click the wclProfileControls Project(or whatever you named your project). Click Add Reference. Or Select the IDE menu item: Project=>Add Reference. Select the .NET tab, Scroll down to System.Design.dll, Click the Select button and Click the OK button to add the reference to the Project.
4.2. New Class
In the Solution Explorer, Right Click the wclProfileControls Project (or whatever you named your project). Select Add. Select Add Class. An Add New Item dialog will pop up with Class preselected (if not, select Class). The name class.cs will be pre filled into the Name text box. Change the name to something more meaningful, such as CountryCodeControlDesigner.cs and Click Open.
4.2.1. Derive from System.Web.UI.Design.ControlDesigner
It is all about leverage, the ControlDesigner will provide a lot of base functionality that you will use. In order to acquire the leverage, change the class definition to derive the class from ControlDesigner:
public class CountryCodeControlDesigner : System.Web.UI.Design.ControlDesigner
4.2.2. GetDesignTimeHtml()
This method is overridden to allow you to change the way the control is rendered in Design View. Add the following to the Class Definition (just after the Constructor):
public override string GetDesignTimeHtml()
{
//cast the underlying Component to a CountryCodeDropDownList
//so that you have access to the design time Property - RenderHTML
CountryCodeDropDownList dl = (CountryCodeDropDownList) Component;
return dl.RenderHTML;
}
4.2.3. GetEmptyDesignTimeHtml()
This method is overridden to allow you to change the way the control is rendered in Design View when it thinks that nothing will be rendered at runtime. It is included here for completeness. This control will always be rendered at runtime. However, if you created a control composed of a Label and did not supply any Text at design time, it is possible that it would be empty at run time. Since this is specified, it will be clear when you look at the control in design view that this is the case. Add the following just after the GetDesignTimeHtml method:
protected override string GetEmptyDesignTimeHtml()
{
//cast the underlying Component to a CountryCodeDropDownList
//so that you have access to the design time Property - NoRenderHTML
CountryCodeDropDownList dl = (CountryCodeDropDownList) Component;
return CreatePlaceHolderDesignTimeHtml(dl.NoRenderHTML);
}
GetEmptyDesignTimeHtml is a protected override and not public like its cousin GetDesignTimeHtml, but it is, so be careful copying and pasting.
5. Designer Attribute
The Designer Attribute is a part of the prolog to the Web Control class definition and tells Visual Studio about the ControlDesigner that is used for the control. It is the link between the Web Control and the Designer. Edit the prolog that appears just before the class definition, CountryCodeDropDownList, in wcCountryCodeDropDownList.cs and add a Designer Attribute.
[
DefaultProperty("Text"),
ToolboxData("<{0}:CountryCodeDropDownList runat=server>{0}:CountryCodeDropDownList>"),
Designer("wclProfileControls.CountryCodeControlDesigner, wclProfileControls")
]
public class CountryCodeDropDownList : System.Web.UI.WebControls.WebControl
{
...
}
- "VS.Net controls, Page 1/5"
- "VS.Net controls, Page 2/5"
- "VS.Net controls, Page 3/5"
- "VS.Net controls, Page 4/5"
- "VS.Net controls, Page 5/5"


