Home All Groups Group Topic Archive Search About
Author
6 Feb 2006 3:14 PM
Allan Ebdrup
I have a custom control, that has several templates (one named Wizard) in it
and I'm trying to develop a ControlDesigner for my control, I've overridden
GetDesignTimeHtml in my Control Designer, and I check that my template is
set and render it at design time using the code:

public override string GetDesignTimeHtml()
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.TextWriter s = new System.IO.StringWriter(sb);
HtmlTextWriter h = new HtmlTextWriter(s);
ContainerControl cc = ((ContainerControl)this.Component);
if (cc.Wizard != null)
{
  // create wizard
  ContainerWizard containerWizard = new ContainerWizard();
  // initialize wizard from template
  cc.Wizard.InstantiateIn(containerWizard);
  containerWizard.RenderControl(h);
}
return sb.ToString();
}

I would like the wizard template to have a special ControlDesigner itself
(inherited from ContainerControlDesigner so I can drag and drop controls
into it), but using the above method my Wizard doesn't get it's own
ControlDesigner

I've created a ControlDesigner for the wizard called ContainerWizardDesigner
and assigned it to my ContainerWizard Class using the
[Designer(typeof(OFiR.Web.Controls.Container.Design.ContainerWizardDesigner))]
attribute.

If only I had a way to manipulate something simular to Page.Controls at
design time instead of only altering the HTML that is output at design time.
I can see that there is a ControlDesigner.ParentControl but I don't see a
controls collection on the ControlDesigner.

If I add a new control to ControlDesigner.Control.Controls in the
GetDesignTimeHtml method it doesn't have any effect on the design view.
Nothing shows up. Can this approach work if controls are added in some other
method (I'm missing something like Page_Init)

How can I add child ControlDesigners in my ControlDesigner?

Kind Regards,
Allan Ebdrup

Author
6 Feb 2006 3:28 PM
Allan Ebdrup
I've found the ControlDesigner.RootDesigner.AddControlToDocument method,
I've tried adding controls in the GetDesignTimeHtml and by overrideing
Initialize But I get the error:
"Operation is not valid due to the current state of object"

Here is my Initialize method:

public override void Initialize(IComponent component)
{
base.Initialize(component);
ContainerControl cc = ((ContainerControl)this.Component);
if (cc.Header != null)
{
  // create header
  ContainerHeader containerHeader = new ContainerHeader();
  // initialize header from template
  cc.Header.InstantiateIn(containerHeader);
  // add header to the child controls collection
  this.RootDesigner.AddControlToDocument(containerHeader, cc,
ControlLocation.LastChild);
}
}

Where should I add child controls in my control designer?

Kind Regards,
Allan Ebdrup
Author
7 Feb 2006 7:58 AM
Steven Cheng[MSFT]
Hi Allan,

Welcome to the ASPNET newsgroup.

From your description, you're developing a template based custom webserver
control, and is wondering how to build a custom control designer which can
programmaticlly add some controls into the control template, correct?

Based on my understanding, the "ControlDesigner.RootDesigner" refer to the
WebForm page's  WebFormRootDesigner, so its "AddControlToDocument" method
is used to add control instance onto web form rather than a sub control.
And for asp.net webserver control, if your control is template based, the
template is actually just plain text (string) which contains some mixed
html or asp.net server control tags ,and this template is parsed at runtime
through the instantialIn method as you've mentioned. Also, if you're going
to make your control capable of being added new child controls
progarmmatically, you can consider define normal child control collection
instead of using template, thus, you can create child control instances
programmatically in CreateChildControl method.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Author
7 Feb 2006 8:36 AM
Allan Ebdrup
"Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message
news:pCdjQx7KGHA.3764@TK2MSFTNGXA02.phx.gbl...
> From your description, you're developing a template based custom webserver
> control, and is wondering how to build a custom control designer which can
> programmaticlly add some controls into the control template, correct?

I have several templates
Wizard, Header, Item, Footer
I'm creating a kind of databound repeater control with a wizard for adding
new items or altering the existing items.
I would like a control designer where I can alter the wizard template (there
is one and only one wizard template) by dragging and dropping controls into
it. And at the same time have a preview of what the repeater part (Header,
Item, Footer) will look like with a dummy datasource.

> Based on my understanding, the "ControlDesigner.RootDesigner" refer to the
> WebForm page's  WebFormRootDesigner, so its "AddControlToDocument" method
> is used to add control instance onto web form rather than a sub control.

I'm not sure what you mean by ""AddControlToDocument" is used to add control
instance onto web form rather than a sub control"
Do you mean that I can't add child control designers? Why does the
this.RootDesigner.AddControlToDocument(containerHeader, cc,
ControlLocation.LastChild);
have a possibility to add controls as children then? Are the controls added
to the webform rather than to the design view?

Or does my insert of the control fail because I have to add a
ControlDesigner, I figured I would just add the Wizard control and then the
system would automatically insert it's associated control designer.

> And for asp.net webserver control, if your control is template based, the
> template is actually just plain text (string) which contains some mixed
> html or asp.net server control tags ,and this template is parsed at
> runtime
> through the instantialIn method as you've mentioned. Also, if you're going
> to make your control capable of being added new child controls
> progarmmatically, you can consider define normal child control collection
> instead of using template, thus, you can create child control instances
> programmatically in CreateChildControl method.

The control works correctly, all I want is to have a design veiw that works
better.

I want the wizard to be template based as the wizard template will be
different every time my control is used, and I would like a design view
where I can alter the Wizard template using drag and drop and see a preview
of the other templates (the other templates are modified in source view)

Kind Regards,
Allan Ebdrup
Author
7 Feb 2006 12:01 PM
Allan Ebdrup
Perhaps I could implement it like a multiview, where you drag a wizard a
header, a item and a footer into the design view of the control?
Author
7 Feb 2006 12:16 PM
Allan Ebdrup
"Allan Ebdrup" <ebdrup@noemail.noemail> wrote in message
news:OLDkG59KGHA.3836@TK2MSFTNGP10.phx.gbl...
> Perhaps I could implement it like a multiview, where you drag a wizard a
> header, a item and a footer into the design view of the control?

That would mean that I don't get a good preview of what the repeater part
will look like.

I could do without the drag and drop functionality in the wizard if I could
only get a design view that reflects how the controls will look at runtime.
If I use the method described in my first post user controls defined in the
page like the telephone control in this example don't get rendered:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>
<%@ Register Assembly="OFiR.Web" Namespace="OFiR.Web.Controls.Container"
TagPrefix="cc2" %>
<%@ Register
Src="Controls/Default/Library/TelephoneNumber/TelephoneNumber.ascx"
TagName="TelephoneNumber" TagPrefix="uc2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc2:ContainerControl ID="ContainerControl1" runat="server">
<Header><uc2:TelephoneNumber ID="TelephoneNumber1" runat="server"
/>Header</Header>
<Wizard>Wizard<uc2:TelephoneNumber ID="TelephoneNumber1" runat="server"
/></Wizard>
<Footer>Footer</Footer>
</cc2:ContainerControl></div>
</form>
</body>
</html>

The telephone custom control is simply ignored when the control is rendered
in the design view, So the output is:
WizardHeaderFooter

No errors are raised.

I would expect the telephone control to be rendered after the Wizard text.
How can I render custom controls present in my wizard template in the design
view?

Kind Regards,
Allan Ebdrup
Author
7 Feb 2006 12:39 PM
Allan Ebdrup
I've taken a look at the example here:
http://www.codeproject.com/aspnet/customdialog.asp
and found a way to edit the wizard template. But my design view still
doesn't render custom controls lik the telephone control mentioned in my
previous post.