CssClass and default images in ServerContol
        Posted  
        
            by Jeff Dege
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jeff Dege
        
        
        
        Published on 2010-03-29T19:00:29Z
        Indexed on 
            2010/03/29
            19:03 UTC
        
        
        Read the original article
        Hit count: 440
        
I'm writing a ServerControl in ASP.NET 3.5, and I'm exposing CssClass, so the user can manipulate the visual appearance of the control. My problem is that I want to establish reasonable defaults, so that the user doesn't have to configure CSS unless he wants to change the defaults.
My specific problem is that my control is emitting html divs, that need to display background images. I want the user to be able to specify a different image in CSS, but I want to display a default background image, and I can't make that work.
The entire server control is emitted as a div, with a class name set to the value the user provided in CssClass. The div that needs the background image is enclosed within this outer div, with a class name of its own. I am currently setting the background image in CSS on the page that contains the control:
   <style type="text/css">
      .cssClass .innerDiv {
         background-image: url("http://....");
      }
   </style>
With this the proper image is drawn. But if it's not there, no image is drawn.
What I want is for the ServerControl to emit some CSS that will define these image urls, that would be over-ridden by any css that was added by the user, and for that default CSS to include URLs to images embedded in the ServerControl's assembly.
And I'm not sure of how to do either. Nor, for that matter, am I sure this is the best approach.
Any ideas?
© Stack Overflow or respective owner