Skip to main content

SharePoint script on demand

This is very old now and exists in market from long time for SharePoint, So thought of summarizing it once.

1.     Create file with name ShareTechPoint.js and below content

function sayHello() {
  alert("Hello");
}
//Notify SharePoint that the custom file has loaded.
SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs("ShareTechPoint.js ");


2.     Now write the below code in another  HTML/ascx/aspx file

<script type="text/ecmascript">
 
    function runCode() {
        SP.SOD.RegisterSod(‘ShareTechPoint.js ', 
                            '/StyleLibrary/ShareTechPoint.js');
        var x = ExecuteOrDelayUntilScriptLoaded(sayHello, 
                              "ShareTechPoint.js ");
    }
 
</script>
 
<input id="Button1" type="button" value="Run Code" 
onclick="runCode()" />


 


This is how you can implement Script on demand for SharePoint.

References
  • http://www.ilovesharepoint.com/2010/08/sharepoint-scripts-on-demand-spsod.html
  • http://www.kalmstrom.com/Tips/SPDevDynamicLoading.html

Comments

Popular posts from this blog

Query SharePoint List - SPQuery vs SPSiteDataQuery vs CrossListQueryInfo

There are three different classes you can use to query SharePoint list:-
1.SPQuery
Used for query a data from a specific list and also used for join two lists.
Use full Links:-
·http://sharepointfordeveloper.blogspot.in/2011/10/step-by-step-spquery-list-joins.html#!/2011/10/step-by-step-spquery-list-joins.html
·http://mysharepointwork.blogspot.in/2010/04/spquery-examples.html

2.SPSiteDataQuery