How to render ControlStyle and other standard attributes?

Discussion in 'ASP .Net Building Controls' started by Ken Baltrinic, Jan 19, 2006.

  1. 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.
    Ken Baltrinic, Jan 19, 2006
    #1
    1. Advertising

  2. Ken Baltrinic

    Teemu Keiski Guest

    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" <> wrote in message
    news:...
    >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.
    >
    >
    >
    Teemu Keiski, Jan 19, 2006
    #2
    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. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,065
    Lau Lei Cheong
    May 15, 2004
  2. =?Utf-8?B?R3JhaGFt?=

    Checkbox control - won't render attributes correctly

    =?Utf-8?B?R3JhaGFt?=, Aug 16, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    529
    =?Utf-8?B?R3JhaGFt?=
    Aug 16, 2005
  3. SAL
    Replies:
    4
    Views:
    1,230
    Zhi-Qiang Ni[MSFT]
    Apr 23, 2010
  4. Sky
    Replies:
    0
    Views:
    271
  5. Glenn Gillen
    Replies:
    0
    Views:
    274
    Glenn Gillen
    Nov 17, 2006
Loading...

Share This Page