How to render ControlStyle and other standard attributes?

K

Ken Baltrinic

I am writing a control that inherits from WebControl. It will be rendered
as a text box, image, and an iframe wrapped in span. Now here is my
problem. I want to render the entire contents more or less myself (i.e
override the Render method) for reasons to complex to explain here.
Everything I want to do is straight forward except for one item. My control
inherits all sorts of standard at WebControl properties, especially the ones
encapsulated in the ControlStyle property. Is there a method somewhere that
will convert the ControlStyle property to the appropriate string (i.g.
"style=\"height: 20px; width:75px\"" or perhas a method that I pass a
writter to and a style and it will call the AddAttribute() method, or
something of this sort. Basically I am trying to avoid coding a method to
build the style attribute from scratch.
 
T

Teemu Keiski

ControlStyle property exposes System.Web.UI.WebControls.Style type, and it
has AddAttributesToRender method, to which you can pass the HtmlTextWriter
instance.

Code could look something like:

if (this.ControlStyleCreated && !this.ControlStyle.IsEmpty)
{
this.ControlStyle.AddAttributesToRender(writer, this);
}

If you use v1.0, AddAttributesToRender signature might not take the owner,
and either of these properties to check for empty style could be non-public.
 

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