concept script in category sharePoint

appears as: scripts, script, scripts
SharePoint 2010 Web Parts in Action

This is an excerpt from Manning's book SharePoint 2010 Web Parts in Action.

Web Parts are interface focused and are the building blocks of many successful SharePoint sites. A good user interface design is user friendly. I’ve discussed how you can add controls and logic to a Web Part; now you’ll explore how you can add images, scripts, and style sheets to your solution. These attached items are resources. This chapter covers two types of resources:

  • Linking and embedding resources such as images, scripts, and style sheets
  • In chapter 4 you saw how to make a style sheet SharePoint theme aware. You added the CSS files into the Layouts/1033/Styles folder. A similar procedure is used to localize other file types. Start with adding the SharePoint Layouts mapped folder. You can safely remove the default folder created with the name of your project. Create one new folder for each culture that’s going to be supported using the LCID number. Scripts are added directly to the culture folder. To use localized scripts in your Web Parts, use the ScriptLink control. Do not hardcode or add the script manually. The ScriptLink control ensures that your JavaScript is included just once in the resulting page. With the ScriptLink control, you specify the name of the script and (optionally) if it’s localized. In a user control, it can look like this:

    If you need to reference the images, scripts, or other files in the manifest files or files that can use resource expressions, you can use the core resource file to get the current LCID. The core resource files contain a resource item that always returns the current UI LCID, like this:

    $Resources:core,Language;

    Finally you always have the option to have values other than text in your resource files. You can use paths to files and scripts that are language dependent in the resource files.