Web Custom Control - Design Time Support ? ? ?

M

MLibby

How do I implement design time support for a web custom control? For some
reason the control can't seem to find System.Web.UI.Design and I get the
following compiler error:

C:\Documents and Settings\MLibby\My Documents\Visual Studio
Projects\CustomControlEnum\CustCtrlDesigner\CustCtrl.cs(3): The type or
namespace name 'Design' does not exist in the class or namespace
'System.Web.UI' (are you missing an assembly reference?)

Here's my code.

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

namespace CustCtrlDesigner
{
/// <summary>
/// Summary description for CustCtrl.
/// </summary>

[DesignerAttribute(typeof(CustCtrlDesigner), typeof(IDesigner))]
public class CustCtrl : System.Web.UI.WebControls.WebControl
{
protected override void Render(HtmlTextWriter output)
{
output.Write("<center><font size='30'>");
output.Write( "Rendered!");
output.Write("</font></center>");
}
}

public class CustCtrlDesigner : System.Web.UI.Design.ControlDesigner
{
public override string GetDesignTimeHtml()
{
string html = base.GetDesignTimeHtml();

output.Write("<center><font size='30'>");
output.Write( "Designer!");
output.Write("</font></center>");
}
}
}
 
S

Steven Cheng[MSFT]

Hi Mlibby,

As for the compile error you mentioned, I think the problem is likely
caused by the required assemblies not
be referenced in your project. Just add the "using ..." statement is not
enought. We should also reference the
the required assemblies via the "Add Reference" function in the VS.NET IDE,
and we need to add the following assemblies:

System.Design.dll

Hope helps. Thanks.

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.)
 
M

MLibby

Thank you Steven, that fixed it.

New question, how do I keep the Render method from outputing during design
mode? Currently both the rendered text and GetDesignTimeHtml text are
showing up in design mode.

Mike
 
S

Steven Cheng[MSFT]

Hi Mike,

I think the problem that the design-time output both the desiger's and the
control's render content is caused by the "base.GetDesignTimeHtml()" you
called. This will return the html using the Control's Render method.

So if you want to use the Designer's output, please comment the

string html = base.GetDesignTimeHtml();

Just use your override code. thanks.

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

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top