Applying Style Objects to Controls

Discussion in 'ASP .Net Building Controls' started by Jesse Sweetland, Feb 18, 2004.

  1. I am writing a custom control that is essentially a scrollable data
    grid with some other custom functionality. I would like to be able to
    specify CSS styles for three row categories: Heading Row, Normal Row,
    and Alternating Row. Subsequently, I have added three read-only
    properties of type System.Web.UI.WebControls.Style named HeadingStyle,
    RowStyle, and AlternatingRowStyle, respectively.

    My preference would be to usee CssStyleCollection for the following
    reasons:

    1. The packaged WebControls use them, and I would like to be
    consistent
    2. CssStyleCollection keys can be iterated over and applied
    generically

    I have the option of using a dummy HtmlGenericControl and using it's
    Style (CssStyleCollection) property as a means of storing the
    CssStyleCollection behind each of my style properties (since I can't
    instantiate a CssStyleCollection) but I chose not to because:

    1. The IDE could not figure out what to do with properties of type
    CssStyleCollection (there is obviously some undocumented attribute I'm
    missing, since the WebControls use it just fine)
    2. There is no way to specify these values at design-time
    3. The IDE handles Style properties just fine

    So, I have 3 Style objects. The CssStyleCollection has a Keys property
    and an indexer that will allow you to iterate over all of the defined
    styles. Style has nothing of the sort. It seems that in order to apply
    the values in Style you have to implement something like the
    following:

    if( ! style.BackColor.Equals( Color.Empty ) )
    {
    myControl.Style["background"] = style.BackColor.Name;
    }

    // etc.

    This seems really tedious. Is there a better way to do this? There is
    a method (ApplyAttributesToRender) that takes an HtmlTextWriter object
    as a parameter. How does this method work? Is this what I need? Am I
    going about this completely wrong?

    Thanks,

    - Jesse
    Jesse Sweetland, Feb 18, 2004
    #1
    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. soulcode
    Replies:
    1
    Views:
    407
    Jason DeFontes
    May 8, 2004
  2. stef
    Replies:
    6
    Views:
    899
  3. Replies:
    1
    Views:
    439
    Andrew Thompson
    Aug 13, 2006
  4. Replies:
    2
    Views:
    1,848
    Toby A Inkster
    Apr 20, 2007
  5. brm6546545
    Replies:
    1
    Views:
    1,014
    Jukka K. Korpela
    Apr 19, 2007
Loading...

Share This Page