Web Custom Control - Design Time Support ? ? ?

Discussion in 'ASP .Net Building Controls' started by MLibby, Sep 3, 2004.

  1. MLibby

    MLibby Guest

    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>");
    }
    }
    }
     
    MLibby, Sep 3, 2004
    #1
    1. Advertising

  2. 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.)
     
    Steven Cheng[MSFT], Sep 4, 2004
    #2
    1. Advertising

  3. MLibby

    MLibby Guest

    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
     
    MLibby, Sep 4, 2004
    #3
  4. 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.)
     
    Steven Cheng[MSFT], Sep 4, 2004
    #4
  5. MLibby

    MLibby Guest

    That worked! Thank you Steven.
     
    MLibby, Sep 4, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    736
  2. onyxring
    Replies:
    0
    Views:
    508
    onyxring
    Feb 15, 2006
  3. =?Utf-8?B?U2ltb24=?=

    Custom Control - Design Time Support

    =?Utf-8?B?U2ltb24=?=, Jan 24, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    344
    =?Utf-8?B?U2ltb24=?=
    Jan 24, 2007
  4. Mark Olbert
    Replies:
    1
    Views:
    527
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Feb 17, 2007
  5. Replies:
    1
    Views:
    400
    Teemu Keiski
    Jul 2, 2003
Loading...

Share This Page