Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

How to load SP.js on a custom .aspx file that doesn't use a masterpage?

$
0
0

Hi,

I created a custom aspx file, and I want to use the sharepoint client object model (javascript). The aspx page is not using a master page. How can I get the SP.js files to load?

Thanks.

This is what I have so far:

<!DOCTYPE HTML><%@ Page Language="C#" %><html dir="ltr" xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta name="WebPartPageExpansion" content="full" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>TEST</title><asp:Content contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server"><SharePoint:ScriptLink language="javascript" name="SP.js" defer="true" runat="server" Localizable="false"/><SharePoint:ScriptLink ID="ScriptLink1" language="javascript" name="core.js" runat="server" /></asp:Content></head><body><form id="form1" runat="server"></form><script type="text/javascript" src="./includes/js/jquery/jquery-2.0.2.min.js"></script><script type="text/javascript">
		// occurs when the document is ready
		$(document).ready(function() {
			alert(1);
			// wait for the sharepoint javascript libraries to load, then call the function 'Initialize'
			ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");
		});
		var listItems;                   // The list of retrieved items.
		var query;                       // For paging, reuse the same query object.
		var targetList;                  // The list from which to retrieve items.
		var clientContext;
		function runCode() {
		    clientContext = new SP.ClientContext();
		    web = clientContext.get_web();  
		    targetList = web.get_lists().getByTitle("Documents");
		    query = new SP.CamlQuery();
		    var CAML = "<View><Query><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy></Query></View>";
		    var CS = "Include(Title,FileRef)";
		    //Specifying the RowLimit will determine how many items will be fetched in one call to the server.
		    query.set_viewXml(CAML);
		    listItems = targetList.getItems(query);
		    clientContext.load(listItems,CS);
		    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
		}
		function onQuerySucceeded(sender, args) {
		    var message = "Titles, two at a time:\n";
		    var listEnumerator = listItems.getEnumerator();
		    while (listEnumerator.moveNext()) {
		        message += "\nTitle=" + listEnumerator.get_current().get_item("Title")
		    }
		    alert(message);
		    //Gets the id of the last element from the returned collection along with the query.
		    var position = listItems.get_listItemCollectionPosition();
		    //Position will be null if all the items in the collection are fetched and there are no more items to be fetched.
		    if (position != null) {
		        //If more items are to be fetched, make a second call to the server and fetch the next group of items.
		        query.set_listItemCollectionPosition(position);
		        listItems = targetList.getItems(query);
		        clientContext.load(listItems);
		        //Call the same function recursively until all the items in the current criteria are fetched.
		        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
		    } 
		}
		function onQueryFailed(sender, args) {
		    alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
		}</script></body></html>

But When I load the page, I get this error:

Content controls have to be top-level controls in a content page or a nested master page that references a master page.


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>