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

Discussion in 'ASP .Net Building Controls' started by Matt Sokol, Aug 6, 2003.

  1. Matt Sokol

    Matt Sokol Guest

    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(CustomControl1Designer))]
    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, Aug 6, 2003
    #1
    1. Advertising

  2. 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


    "Matt Sokol" <> wrote in message
    news:...
    > 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(CustomControl1Designer))]
    > 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, Aug 6, 2003
    #2
    1. Advertising

  3. 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 http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Theo Tillotson, Aug 7, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leeor Chernov
    Replies:
    2
    Views:
    789
    Leeor Chernov
    Oct 16, 2005
  2. Vincent Scheel
    Replies:
    0
    Views:
    422
    Vincent Scheel
    Mar 20, 2006
  3. Replies:
    3
    Views:
    367
  4. Vincent Scheel

    ControlDesigner does not "repaint" control when properties are changed

    Vincent Scheel, Mar 20, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    162
    Vincent Scheel
    Mar 20, 2006
  5. Serge Kruppa
    Replies:
    0
    Views:
    237
    Serge Kruppa
    Oct 4, 2006
Loading...

Share This Page