Search code examples
c#asp.netdesigner

ASP.NET user control designer support


I have a user control which when added to the markup via the Toolbox or manually typing <myNameSpc:myCtrl ... I would like to spit out:

<myNameSpc:myCtrl>

     <template></template>

</myNameSpc:myCtrl>

I remember doing this for windows workflows and it involved implementing something like a TypeConverter and WorkflowXmlSerializer so it maybe possible for user controls as well I'd guess ? the only thing is that I don't have time to research this matter now, so I was wondering if anyone would be kind enough to point me in the right direction so that I don't have to dig deep into the designer serialization of VS (which I remember was a big pain).


Solution

  • For your custom control, you can specify a ToolboxDataAttribute which defines the default html that will be generated when you drag a control onto the design service. E.g.:

    [ToolboxData("<{0}:myCtrl runat="server"><template></template></{0}:myCtrl>")]
    public class myCtrl : System.Web.UI.Control
    {
    
    }