Problems creating a Designer

K

Kjetil Nordahl

In designview of the WebForm, my control shows the error message: "Error
Creating Control - ReportDate1 (i)".

Failed to create designer
'System.Windows.Forms.Design.ComponentDocumentDesigner,
System.Design, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'

What is wrong?
The webcontrol is working, but I would like the designer to work too...
 
K

Kjetil Nordahl

Ok. I think I found the problem. It works now, anyway!

The problem was in the [Designer()] on the control-class.
the string-parameter to Designer should be:

[Designer("namespace-name.designerclass-name, assembly-name")]
 
K

Kurt Yokum

Could use drop in a code sample that includes this Designer syntax? I am not
familiar with where this would go in the code.

Thanks,
Kurt
 
K

Kjetil Nordahl

Here is an example on a webcontrol with a designer. This designer should show
a dropdownlist with the item "design-time item".

using System;
using System.ComponentModel;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;

namespace MyCompany.MyControls
{
[ToolboxData("<{0}:MyWebControl runat=server></{0}:MyWebControl>"),
Designer("MyCompany.MyControls.MyWebControlDesigner, MyWebControl")]
public class MyWebControl : WebControl
{
....
}

public class MyWebControlDesigner : ControlDesigner
{
public override string GetDesignTimeHtml()
{
MyWebControl ctrl = (MyWebControl)Component;

// create the html-writer
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);

// add a control that you want to show at design-time
DropDownList designTimeDropDownList = new DropDownList();
designTimeDropDownList.Items.Add("design-time item");

// get design-time styles and formatting from your control
MyWebControl ctrl = (MyWebControl)Component;
designTimeDropDownList.CssClass = ctrl.CssClass;

// let the design-time control render itself on the html-writer
designTimeDropDownList.RenderControl(tw);

// return the html-code from the html-writer
return sw.ToString();
}
}
}

Also add the following code to the AssemblyInfo.cs-file to get a nice
tag-prefix (<abc:MyWebControl runat="server" />)

using System.Web.UI;
[assembly: TagPrefix("MyCompany.MyControls", "abc")]


Kurt Yokum said:
Could use drop in a code sample that includes this Designer syntax? I am not
familiar with where this would go in the code.

Thanks,
Kurt

Kjetil Nordahl said:
Ok. I think I found the problem. It works now, anyway!

The problem was in the [Designer()] on the control-class.
the string-parameter to Designer should be:

[Designer("namespace-name.designerclass-name, assembly-name")]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top