Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > How to render ControlStyle and other standard attributes?

Reply
Thread Tools

How to render ControlStyle and other standard attributes?

 
 
Ken Baltrinic
Guest
Posts: n/a
 
      01-19-2006
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.



 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      01-19-2006
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.


--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Ken Baltrinic" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
>
>
>



 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Skin ControlStyle of templated fields in DetailsView SAL ASP .Net 4 04-23-2010 08:58 AM
Accessing rails render method outside of view / Decorating render Glenn Gillen Ruby 0 11-17-2006 02:30 PM
Deep confusion:use ControlStyle, or Style statebag? Sky ASP .Net Web Controls 0 07-11-2004 05:25 PM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM



Advertisments