How to use CssStyleCollection for a UserControl?
asp.net, c#, css, custom-controls
Solution
CssStyleCollection is created from a Style object; a Style object has a GetStyleAttributes method that returns a CssStyleCollection, so create a Style object, assign all the props you want, and return CssStyleCollection. Also, it requries IUrlResolutionService, which is a reference to the page or a control.
Problem
I am wanting to do custom rendering of the CSS styling, as such I created a new UserControl. From there, I thought it'd be easy just create a new CssStyleCollection under the name Style. It does not work though! How do I make this code compile? (just an example) ``` class MyControl : UserControl{ CssStyleCollection Style=new CssStyleCollection(); //compiler error on the `new..` } ``` I don't understand what I am doing wrong here. CssStyleCollection is a sealed class, but it is not static. How do I instantiate a new one!? Also, the compiler error given is The type System.Web.UI.CssStyleCollection has no constructors defined