1)
WebControl.Style ( MSDN ):
Controls have WebControl.Style property that returns a CssStyleCollection, which contains the HTML style attributes to render on the outer tag of the server control.
CssStyleCollection ( MSDN ):
Any style declared for a particular HTML server control is added to the collection when the containing Web Forms page is parsed.
a)
As far as I understand the above quotes, before the server control – for example GridView - is parsed, all the styles declared for GridView, which includes GridView.RowStyle and GridView.BorderColor etc, are added to GridView.Style collection ( which is of type CssStyleCollection )?
Thus when GridView is parsed, Asp.Net doesn’t for example check the GridView.RowStyle property and then render corresponding html style attributes accordingly, but instead it first transfers all of the GridView’s styles to CssStyleCollection, and only then checks which html style attributes to render for that control?
b) If my above assumption is correct ( which I doubt ) – why doesn’t Asp.Net simply check GridView’s style properties ( like GridView.BorderColor etc ) and render appropriate html style attributes accordingly? What is the point of adding all those styles to CssStyleCollection and only then rendering appropriate attributes?
2) WebControl.Style ( MSDN ):
Controls have WebControl.Style property that returns a CssStyleCollection, which contains the HTML style attributes to render on the outer tag of the server control.
I assume lots of web server controls ( like GridView ) contain style attributes which will get rendered on inner tags of a html control. Is the text suggesting that those attributes aren’t added to WebControl.Style collection? If not, why not?
thanx
Everything within a Style object gets rendered appropriately, or at least where that control wants to render it (for instance, RowStyle gets rendered for a gridview row, whereas the EmptyDataStyle gets rendered for the container rendering the empty message), so it's up to the control to render it.
If you use .NET reflector, it can tell you that Style does not inherit from CssStyleCollection, but has a method (GetStyleAttributes) that can convert the Style object to a CssStyleCollection collection, which is used for rendering).
HTH.
精彩评论