public static void SandboxRegisterClientScriptBlock(string scriptId, string scriptUrl,Page page)
{
//Add script control.
HtmlGenericControl addJscript = new HtmlGenericControl("script");
addJscript.Attributes.Add("type", "text/javascript");
//Checks if the script is already loaded and if not, load it.
addJscript.InnerHtml = @"function CheckScriptAndLoad() {
//Check if script is loaded. Return true if yes, else return false.
var isScriptLoaded = function (scriptId) {
if (document.getElementById(scriptId) != null) {
return true;
}
else {
return false;
}
}
//If script is not loaded, create a DOM element with specified script id and url.
if (!isScriptLoaded('" + scriptId + @"')) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.id = '" + scriptId + @"';
script.src = '" + scriptUrl + @"';
document.body.appendChild(script);
}
}
_spBodyOnLoadFunctionNames.push('CheckScriptAndLoad');";
page.Controls.Add(addJscript);
}