Accessing ControlDesigner from control?

Discussion in 'ASP .Net Building Controls' started by Carole MacDonald, Aug 15, 2004.

  1. I'm trying to do the following:

    public class MyControlDesigner : System.Web.UI.Design.ControlDesigner
    {
    private string m_html = "";
    public string Html
    {
    get { return m_html; }
    set { m_html = value; }
    }
    public override string GetDesignTimeHtml()
    {
    return m_html;
    }
    }

    [DesignerAttribute(typeof(MyControlDesigner), typeof(IDesigner))]
    public class MyControl : System.Web.UI.WebControls.WebControl
    {
    override void OnInit(EventArgs e)
    {
    System.ComponentModel.AttributeCollection attributes =
    TypeDescriptor.GetAttributes(this);

    DesignerAttribute myAttribute =
    (DesignerAttribute)attributes[typeof(DesignerAttribute)];

    // somehow set the Html property of the designer to a string
    }
    }

    Where I'm stuck is getting an object reference to MyControlDesigner.
    Is this possible? The reason I'm trying to do this is I have a bunch
    of custom web controls where I want the GetDesignTimeHtml() to return
    a simple string that will be different for each control. I'd rather
    not create a different control designer for each one since they'd
    basically be identical except for the returned string. My first
    thought was to derive from DesignerAttribute so I could pass in
    another argument with the html string, but that is a sealed class. So
    then I tried to access the ControlDesigner to set the string
    dynamically. Is this possible?

    Thanks,
    Carole
     
    Carole MacDonald, Aug 15, 2004
    #1
    1. Advertising

  2. Hi Carole,

    The code for generating the design-time html of a control should really go
    into a control designer and not the control itself. If you want to have a
    common control designer for different type of controls while offering a
    customized design-time rendering for each one, then you could add such code
    in the ControlDesigner.GetDesignTimeHtml method where you could check the
    control type that the particular instance of the designer was initialized
    with.

    Let me know if you need more help on this issue,

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    My profile: http://aspnet2.com/mvp.ashx?vga


    "Carole MacDonald" <> wrote in message
    news:...
    > I'm trying to do the following:
    >
    > public class MyControlDesigner : System.Web.UI.Design.ControlDesigner
    > {
    > private string m_html = "";
    > public string Html
    > {
    > get { return m_html; }
    > set { m_html = value; }
    > }
    > public override string GetDesignTimeHtml()
    > {
    > return m_html;
    > }
    > }
    >
    > [DesignerAttribute(typeof(MyControlDesigner), typeof(IDesigner))]
    > public class MyControl : System.Web.UI.WebControls.WebControl
    > {
    > override void OnInit(EventArgs e)
    > {
    > System.ComponentModel.AttributeCollection attributes =
    > TypeDescriptor.GetAttributes(this);
    >
    > DesignerAttribute myAttribute =
    > (DesignerAttribute)attributes[typeof(DesignerAttribute)];
    >
    > // somehow set the Html property of the designer to a string
    > }
    > }
    >
    > Where I'm stuck is getting an object reference to MyControlDesigner.
    > Is this possible? The reason I'm trying to do this is I have a bunch
    > of custom web controls where I want the GetDesignTimeHtml() to return
    > a simple string that will be different for each control. I'd rather
    > not create a different control designer for each one since they'd
    > basically be identical except for the returned string. My first
    > thought was to derive from DesignerAttribute so I could pass in
    > another argument with the html string, but that is a sealed class. So
    > then I tried to access the ControlDesigner to set the string
    > dynamically. Is this possible?
    >
    > Thanks,
    > Carole
     
    Victor Garcia Aprea [MVP], Aug 15, 2004
    #2
    1. Advertising

  3. "Carole MacDonald" <> wrote in message
    news:...
    > I'm trying to do the following:


    <snip>

    > Where I'm stuck is getting an object reference to MyControlDesigner.
    > Is this possible? The reason I'm trying to do this is I have a bunch
    > of custom web controls where I want the GetDesignTimeHtml() to return
    > a simple string that will be different for each control. I'd rather
    > not create a different control designer for each one since they'd
    > basically be identical except for the returned string. My first
    > thought was to derive from DesignerAttribute so I could pass in
    > another argument with the html string, but that is a sealed class. So
    > then I tried to access the ControlDesigner to set the string
    > dynamically. Is this possible?


    Carole, the designer architecture is structured so that the designer may
    access the control, but not vice-versa.

    Are you aware that you could use the same designer for all of your web
    controls? That designer could then output a different string for each
    control by checking to see which control type it was designing.

    If you need to configure the "simple string" through attributes, then you
    could create your own attribute separate from DesignerAttribute, and pass
    the string in the attribute constructor. Then, the designer could look for
    that attribute and display it in the returned HTML.
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Aug 15, 2004
    #3
  4. "John Saunders" <> wrote in message news:<eQ#>...
    > "Carole MacDonald" <> wrote in message
    > news:...
    > > I'm trying to do the following:

    >
    > <snip>
    >
    > > Where I'm stuck is getting an object reference to MyControlDesigner.
    > > Is this possible? The reason I'm trying to do this is I have a bunch
    > > of custom web controls where I want the GetDesignTimeHtml() to return
    > > a simple string that will be different for each control. I'd rather
    > > not create a different control designer for each one since they'd
    > > basically be identical except for the returned string. My first
    > > thought was to derive from DesignerAttribute so I could pass in
    > > another argument with the html string, but that is a sealed class. So
    > > then I tried to access the ControlDesigner to set the string
    > > dynamically. Is this possible?

    >
    > Carole, the designer architecture is structured so that the designer may
    > access the control, but not vice-versa.
    >
    > Are you aware that you could use the same designer for all of your web
    > controls? That designer could then output a different string for each
    > control by checking to see which control type it was designing.
    >
    > If you need to configure the "simple string" through attributes, then you
    > could create your own attribute separate from DesignerAttribute, and pass
    > the string in the attribute constructor. Then, the designer could look for
    > that attribute and display it in the returned HTML.


    Thanks for the tips and suggestions. I was trying to keep things too
    simple, I think, in that I didn't want to have to update both the
    Control Designer and the Control when I added a new control. But
    based on the responses, I've added a check in the Control Designer to
    see what type of control it is and output the respective HTML.

    Thanks again,
    Carole
     
    Carole MacDonald, Aug 16, 2004
    #4
    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. =?Utf-8?B?S0NT?=
    Replies:
    0
    Views:
    489
    =?Utf-8?B?S0NT?=
    Sep 22, 2005
  2. Vincent Scheel
    Replies:
    0
    Views:
    432
    Vincent Scheel
    Mar 20, 2006
  3. cruster

    ASP.NET ControlDesigner & smart tags

    cruster, Apr 29, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    441
    cruster
    Apr 29, 2007
  4. Matt Sokol
    Replies:
    2
    Views:
    428
    Theo Tillotson
    Aug 7, 2003
  5. Vincent Scheel

    ControlDesigner does not "repaint" control when properties are changed

    Vincent Scheel, Mar 20, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    170
    Vincent Scheel
    Mar 20, 2006
Loading...

Share This Page