Link to home
Start Free TrialLog in
Avatar of ozymandias
ozymandiasFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Custom ASP.NET Control - Design-time rendering

I have created a custom asp.net web control.

I have done this by extending System.Web.UI.WebControls.Panel like this :


      [DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
      public class WebCustomControl1 : System.Web.UI.WebControls.Panel{
      }

Internally I have added some labels, buttons and textboxes to the panel, exposed some bindable attributes and events etc.
I have added it to my toolbox and can drag and drop it onto the form.
It all works fine and renders beautifully on the web page.
However, in the VS2003 designer it only renders the outer panel and not the inner controls.
How can I get it to look like it does at runtime in design time ?
Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

OK. I think I have solved this. Just adding a ControlDesigner derived class seems to make it work.

      [DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
      [DesignerAttribute(typeof(WebCustomControl1Designer), typeof(IDesigner))]
      public class WebCustomControl1 : System.Web.UI.WebControls.Panel{

      }

      public class WebCustomControl1Designer : System.Web.UI.Design.ControlDesigner {


            public WebCustomControl1Designer() : base() {
                  
            }


      }
I thought I might have to override some of the methods of the ControlDesigner but I don't, so in fact the answer is just to add this :

[DesignerAttribute(typeof(System.Web.UI.Design.ControlDesigner), typeof(IDesigner))]

to the class declaration.
ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial