Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Matt Sokol #1
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
-
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... -
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... -
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... -
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,... -
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... -
John Saunders #2
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
-
Theo Tillotson #3
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



Reply With Quote

