Use another s-control as a CSS file

If you build a number of s-controls that provide custom web UIs to the users, you are probably using styles for formatting the page. This is usually done within a < style > tag inside the s-control. If you have a number of s-controls that produce a similar look and feel, then you are probably copying the styles to each s-control. To change the design, you end up making changes in each s-control.

I was doing some s-control development recently and I got to thinking whether I could maintain my styles in a separate s-control and then reference that s-control like I would a CSS file. It worked! This is synonymous with maintaining a separate CSS file on your web server rather than embedding the styles within a < style > tag. This will allow you to change the styles of all of your s-controls from a single location.

An example of referencing an s-control as a CSS file is below. To reference an s-control containing your styles, simply use the the following code.

< link href="/servlet/servlet.Integration?lid={ID_OF_YOUR_CSS_S-CONTROL}” type=”text/css” rel=”stylesheet” >

Depending upon the amount of s-control development you do, this may or may not be necesary. But it’s a cool trick to know if you need it.

If you are developing something to upload to AppExchange for others to use, be careful going this route because the ID of the s-control you reference will be different in each Org your package gets downloaded to.


  1. Kingsley Joseph Said,

    May 5, 2006 @ 7:27 pm

    Daroz might have to give his “heretic” title up to you

  2. steve Said,

    May 5, 2006 @ 8:31 pm

    Yeah, and it would work as well for javascript libraries that you build up. Same idea, just a < script > tag instead of a link tag.

    I was thinking about having a constants file. It would hold:
    * The ID’s for the various recordtypes I use in opportunity creation, and reference in a lot of different S-Controls
    * The Id of the “Individual” Account where I throw all my B2C Contacts
    * Naming conventions for Opportunities
    * Assorted other site-wide values, like home state for the Contact and Household creation form

    Great post.

RSS feed for comments on this post