0

I'm working on my first web part and was wondering if there is a way to create a custom resource (like a WPProperty) that would link CSS to the webpart just as you can control the XSLT of a XSLTViewPart (which, ironically I'm inheriting from). The reason for this is we're looking to make a shareable resource that would work with different lists that we want to represent differently.

I was thinking of adding a CSSLink or CSSRegistration into the code-behind, but then I thought it would be packaged along with the .DLL and not editable. Am I wrong?

1 Answer 1

2

To add a CSS file to a Web Part you can do following.

  1. Map Layouts folder in Visual Studio

  2. Add CSS file to the Mapped Folder (i.e.: If the Project Name is SPTest then add the file to Layouts/SPTest/ folder)

Then add following code to the WebPart's .ascx file

<Sharepoint:CssLink ID="CssLink1" runat="server" />
<SharePoint:CssRegistration ID="CssRegistration1" Name="/_layouts/SPTest/Test.css" runat="server" />

SharePoint 2010 doesn't really need the Sharepoint:CssLink.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.