SharePoint script on demand

Very old 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

function runCode() {
SP.SOD.RegisterSod(‘ShareTechPoint.js ‘,

                            '/StyleLibrary/ShareTechPoint.js');
        var x = ExecuteOrDelayUntilScriptLoaded(sayHello, 
                              "ShareTechPoint.js ");
    }

<input id=”Button1″ type=”button” value=”Run Code”

onclick="runCode()" />
This is how you can implement Script on demand for SharePoint.
References

 

 

Advertisements

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