basquang™ on clouds

October 14, 2010

ECMAScript: SP.ClientContext is undefined or null

Filed under: ECMAScript,SharePoint — basquang @ 9:26 AM

Sometime We cannot use SP.ClientContext in Site pages, Web part pages or Application pages. Although We was following this guide from msdn

Setting Up an Application Page for ECMAScript

If so, please replace the below lines

<script type=”text/ecmascript” src=”/_layouts/SP.Core.js” />
<script type=”text/ecmascript” src=”/_layouts/SP.Debug.js” />
<script type=”text/ecmascript” src=”/_layouts/SP.Runtime.Debug.js” />

With

<SharePoint:ScriptLink ID=”ScriptLink1″ Name=”sp.debug.js” LoadAfterUI=”true” Localizable=”false” runat=”server” />

Reference MSDN

Advertisements

2 Comments »

  1. When using SharePoint online i found this code to work.

    var clientContext;

    ExecuteOrDelayUntilScriptLoaded(initialize,”SP.js”);

    function initialize() {

    this.clientContext = SP.ClientContext.get_current();

    }

    The strange part is that it works on some websites without the above code. Can anyone explain this?

    Comment by hrhenrikandersen — August 31, 2011 @ 2:28 PM | Reply

  2. Thank you – this worked perfectly!

    Comment by Jerry Cote — February 3, 2015 @ 3:35 AM | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: