Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Accessing ControlDesigner from control?

Reply
Thread Tools

Accessing ControlDesigner from control?

 
 
Carole MacDonald
Guest
Posts: n/a
 
      08-15-2004
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
 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      08-15-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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



 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      08-15-2004
"Carole MacDonald" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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


 
Reply With Quote
 
Carole MacDonald
Guest
Posts: n/a
 
      08-16-2004
"John Saunders" <(E-Mail Removed)> wrote in message news:<eQ#(E-Mail Removed)>...
> "Carole MacDonald" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET ControlDesigner & smart tags cruster ASP .Net 0 04-29-2007 12:00 AM
ControlDesigner does not "repaint" control when properties are changed Vincent Scheel ASP .Net 0 03-20-2006 07:21 AM
How to get parent/controldesigner of STANDARD webcontrol =?Utf-8?B?S0NT?= ASP .Net 0 09-21-2005 11:05 PM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM
System.Web.UI.Design.ControlDesigner never calls GetErrorDesignTimeHtml on Exceptions John Saunders ASP .Net Building Controls 3 08-05-2003 02:12 AM



Advertisments