M
Matt Sokol
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
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