by Oscar
2. September 2009 11:17
So, you have a WebPart you have developed and you are deploying it as part of a Solution (at least you should be). Your WSP includes CSS, Images and other artifacts that are dropped into the _layouts folder when your featureis activated.
Now you need a way to ensure that the CSS Classes you are referencing on your WebPart code are available to the WebPart, BUT you do not want the person deploying the WebPart to modify the Master Page. In other words, your WebPart should not have any dependencies outside of your Solution.
There is a way to simply add a CSS link within code. You can use the Class available on the Object Model
protected override void CreateChildControls()
{
Microsoft.SharePoint.WebControls.CssLink cssLink = new Microsoft.SharePoint.WebControls.CssLink();
cssLink.DefaultUrl = "/_layouts/MyAppFolder/CSS/tabBasic.css";
this.Page.Header.Controls.Add(cssLink);
more code………
Simple yet effective!
-Oscar