ControlDesigner not invoked on custom control when control is rendered within another custom control

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default ControlDesigner not invoked on custom control when control is rendered within another custom control

    I have a custom control that has a simple designer (derived from
    System.Web.UI.Design.ControlDesigner) associated with it (using the
    DesignerAttribute). The overriden GetDesignTimeHtml provides the
    design-time display correctly when this control is placed on a web
    form.

    My problem is I also want to use this control within another custom
    control as a child. However, when the parent renders in design-time,
    the child control does not use its designer and renders as if in
    run-time. I have debugged the designer using another instance of
    VS.NET and it is clear that the custom designer is not invoked and the
    normal Render method of the child control is called.

    Is this a bug or by design? Or am I missing something that will allow
    the custom designer to be invoked when the control is being rendered
    within another custom control?

    Here is a very simple example of what I'm talking about, if you place
    both controls on a web form you will see what I mean:

    [System.ComponentModel.Designer(typeof(CustomContro l1Designer))]
    public class CustomControl1 : System.Web.UI.WebControls.Label
    {
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
    this.Text = "This is the run-time display.";
    base.Render (writer);
    }
    }

    public class CustomControl1Designer :
    System.Web.UI.Design.ControlDesigner
    {
    public override string GetDesignTimeHtml()
    {
    return "This is the design-time display.";
    }
    }

    public class CustomControl2 : System.Web.UI.WebControls.WebControl
    {
    protected override void CreateChildControls()
    {
    System.Web.UI.WebControls.Label label = new
    System.Web.UI.WebControls.Label();
    label.Text = "Result of CustomControl1 rendering: ";
    Controls.Add(label);
    CustomControl1 control1 = new CustomControl1();
    Controls.Add(control1);
    }
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
    EnsureChildControls();
    base.Render (writer);
    }
    }


    Thanks,

    Matt Sokol
    Matt Sokol Guest

  2. Similar Questions and Discussions

    1. Best Practices: Porting ASCX control to compiled Custom Control?
      Hi There! What is the best way to port the ASCX control to complied Custom Control (i.e. DLL)? Please share some pointers. Also, can many ASCX...
    2. Keep custom property-value in custom rendered control
      Hi there, here's the thing I have a custom control (rendered) with a label, textbox and some validators. I use that for entering a birthdate, to...
    3. Repeater control in a rendered custom control
      I have created a custom control that puts a html wrapper around some code so <myc:cPanel ...>more html</myc:cPanel> will draw a html table which...
    4. Page Load fired 3 times Web user control is embedded in a custom control
      Hi, I have built a custom control that build a table with 3 cells in it. The custom control is designed to add all child controls to cell#2,...
    5. Using Table control in a custom composite control. Control does not render properly in design time.
      All, I have written a very simple custom composite control that includes a control of type System.Web.UI.WebControls.Table. The control...
  3. #2

    Default Re: ControlDesigner not invoked on custom control when control is rendered within another custom control

    Matt, I believe that this is by design. Your simple designer would show up
    if it were inside of a Panel or Template, but the infrastructure for that
    isn't available to us mere mortals.

    Now, on the other hand, since it's one of your controls within another of
    your controls, perhaps you could expose the render functionality of the
    inner designer in such a way that the outer designer could get at it. If the
    inner designer had a public static method like "static string
    RenderMyControl(MyControl control)", then the outer designer should be able,
    during its GetDesignTimeHtml, to find the designer of the inner control and
    to invoke this RenderMyControl method to get the HTML.

    You'd want to have the inner designer GetDesignTimeHtml call
    RenderMyControl, or have them both call common code, just to keep the output
    the same between the two of them...
    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]

    "Matt Sokol" <msokol@myrealbox.com> wrote in message
    news:8b2a733.0308060720.31bd64f4@posting.google.co m...
    > I have a custom control that has a simple designer (derived from
    > System.Web.UI.Design.ControlDesigner) associated with it (using the
    > DesignerAttribute). The overriden GetDesignTimeHtml provides the
    > design-time display correctly when this control is placed on a web
    > form.
    >
    > My problem is I also want to use this control within another custom
    > control as a child. However, when the parent renders in design-time,
    > the child control does not use its designer and renders as if in
    > run-time. I have debugged the designer using another instance of
    > VS.NET and it is clear that the custom designer is not invoked and the
    > normal Render method of the child control is called.
    >
    > Is this a bug or by design? Or am I missing something that will allow
    > the custom designer to be invoked when the control is being rendered
    > within another custom control?
    >
    > Here is a very simple example of what I'm talking about, if you place
    > both controls on a web form you will see what I mean:
    >
    > [System.ComponentModel.Designer(typeof(CustomContro l1Designer))]
    > public class CustomControl1 : System.Web.UI.WebControls.Label
    > {
    > protected override void Render(System.Web.UI.HtmlTextWriter writer)
    > {
    > this.Text = "This is the run-time display.";
    > base.Render (writer);
    > }
    > }
    >
    > public class CustomControl1Designer :
    > System.Web.UI.Design.ControlDesigner
    > {
    > public override string GetDesignTimeHtml()
    > {
    > return "This is the design-time display.";
    > }
    > }
    >
    > public class CustomControl2 : System.Web.UI.WebControls.WebControl
    > {
    > protected override void CreateChildControls()
    > {
    > System.Web.UI.WebControls.Label label = new
    > System.Web.UI.WebControls.Label();
    > label.Text = "Result of CustomControl1 rendering: ";
    > Controls.Add(label);
    > CustomControl1 control1 = new CustomControl1();
    > Controls.Add(control1);
    > }
    > protected override void Render(System.Web.UI.HtmlTextWriter writer)
    > {
    > EnsureChildControls();
    > base.Render (writer);
    > }
    > }
    >
    >
    > Thanks,
    >
    > Matt Sokol

    John Saunders Guest

  4. #3

    Default Re: ControlDesigner not invoked on custom control when control is rendered within another custom control



    I am dealing with the same issue. Is there any reference to how the
    default ControlDesigner that is invoked by MyBase..GetDesignTimeHtml
    generates the design-time html?

    One alternative I've been thinking about was to ignore the control
    during design-time display. Setting it's Visibility to false
    temporarally, which is similar to what is done with Validator controls
    sometimes in MS examples.

    I like Johns idea, and although I haven't tried it, I'm not sure that it
    would work since the output would be asymetric to the actual WISYWIG
    layout; meaning... that the HTML of the child control would either come
    before or after the rest of the parent's design time html. Imbedding it
    at the proper location in the stream is the trickiest part of that
    idea.... if I'm not just way off base.

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Theo Tillotson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139