If you're developing a custom webcontrol which doesn't have an UI to be displayed in Visual Studio's design time, like this NonVisualControlAttribute indicates, you may want to display the default gray rectangular box. You can accomplish it by doing the following:
- Create a new class. Name it <yourcontrolname>Designer and make it override System.Web.UI.Design.ControlDesigner. Include a reference to System.Design if not already present.
- In this newly created class, add an override of the public string GetDesignTimeHtml() method.
- In this overriden GetDesignTimeHtml method, add the following code:
return base.CreatePlaceHolderDesignTimeHtml();
If you want to add some custom text in the gray box, use the following line instead:
return base.CreatePlaceHolderDesignTimeHtml("some text to display in design mode"); - Above your class declaration which holds the custom control you're creating, add the following attribute:
[DesignerAttribute(typeof(<name of the class created at step #1>))]
- Build your project. Now when adding your custom control from the Visual Studio Toolbox in Design mode onto an ASPX form, it will display the standard gray box where your custom control is inserted!