Javascript/ECMAScript – Client Object Model

Javascript – Client Object Model reference: _layouts/sp.js, add this using <Sharepoint:ScriptLink>

Use un-crunched *.debug.js by adding <Sharepoint:ScriptLink…. ScriptMode=”Debug”/> Not fur production though. For trouble-shooting/debug only because you can see the *.js file.

Can’t talk to a different site; you can with Silverlight though.

ECMAScript object model can only be used in Sharepoint site, not other ASP.NET site.
Can’t access site in different domains.
Can use jQuery. Just add reference to it.
Can use ECMAScript on a Sharepoint application page. Just add reference (as mentioned above)
To update with Javascript, need to add a FormDigest tag in for security purpose.

Add in ASCX control: (there is another version of sp.js called sp.debug.js)

If you do update, need to add a ForfDigest tag, inside <Form>

By calling getWebProperties method from any web part, you can get the current web’s title, id and creation date.

Load only the title, id and created date.

Make sure that your javascript runs after sp.js is loaded:

Update scenario:

get an property use get_propertyName and to set a property use set_propertyName.

Abou FormDigest

For reasons of security, by default, Microsoft SharePoint Foundation does not allow you to make posts from a Web application to modify the contents of the database unless you include security validation on the page making the request.

You can update data for a single site or for a site collection by adding a (1) page directive and (2) a FormDigest control to the page that makes the request. The following directive registers the Microsoft.SharePoint.WebControls namespace:

<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

<form id=”Form1″ method=”post” runat=”server“><SharePoint:FormDigest ID=”MyFormDigest” runat=”server”/><asp:Button id=”Button1″ style=”Z-INDEX: 101; LEFT: 282px; POSITION: absolute; TOP: 282px” runat=”server” Text=”Button”></asp:Button></form>

Inserting this control on an ASPX page generates a security validation, or message digest, to help prevent an attack wherein a user is tricked into posting data to the server. The security validation is specific to a user, site, and time period and expires after a configurable amount of time. When the user requests a page, the server returns the page with security validation inserted. When the user then submits the form, the server verifies that the security validation has not changed.

Not avalable in Sandbox solution.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: