Hmm – and interesting problem; in the Sandbox you don’t have any access to the CssRegistration class. It’s in the Microsoft.SharePoint.WebControls namespace, and you don’t have access to that.
<Link> tag into the
<Head> of the page.
Clever, but yuck!
The explanation that I came across by Mukul Sabharwal (and seemed pretty good) was:
Sandbox webparts do not execute in the same ASP.NET context as the page in which they reside, instead they execute in a distince ASP.NET context in a seperate worker process (UserCode Worker Process). SharePoint setups a make-believe world for the WebPart — specifically this make believe world consists of a single page with a single webpart zone and a single webpart — your sandbox webpart.
Once the webpart finishes execution the result is returned back to the main page. In fact, even if RegisterCssReference was not internal, there is no guarantee that the CSS could be applied, because we may have be too late in the ASP.NET page lifecycle to go do that.
This brings me to to answering your question, which is it is not currently possible to specify CSS into a page for a Sandbox Web Part.
Makes sense – but some way of registering CSS might be useful.
Edit: I tested Ali Robertson’s comment about just putting the
link tag directly in the page, and that works.Unfortunately, there’s no way of then resolving Themed CSS files – something the CssRegistration class does – so you can’t have themed CSS in sandbox solutions (at least, as far as I can see at the moment).