Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Applying Style Objects to Controls

Reply
Thread Tools

Applying Style Objects to Controls

 
 
Jesse Sweetland
Guest
Posts: n/a
 
      02-18-2004
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
 
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
Applying a style sheet only to a single div russell.allbritain@gmail.com HTML 2 04-20-2007 09:43 AM
Applying CSS style to dynamically generated XML galpi@mail.com Java 1 08-13-2006 08:07 PM
Programmatically Applying Style Sheets.... soulcode ASP .Net 1 05-08-2004 10:09 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
Applying a Style to Individual Characters stef HTML 6 10-16-2003 01:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57