Category Archives: Javascript




Adding Javascript to a sandboxed Visual Web Part

Adding JavaScript to a sandboxed Visual Web Part seems to work best when using the following script inside the .ascx file: <script type="text/javascript">     SP.SOD.executeFunc("~sitecollection/_catalogs/siteassets/MyWebPart/MyWebPartScript.js", null, LoadMyScript);     //the following two variables keep the page with the web part from freezing and becoming uneditable when in edit mode     var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;     var wikiInEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;     if […]


Can’t get JavaScript files to run in SharePoint?

Having trouble getting JavaScript files to run in your SharePoint site? Make sure you set the LoadAfterUI=”true” attribute in your ScriptLink tag. Here is an example: <SharePoint:ScriptLink ID=”MyBaseID” Name=”~Site/_catalogs/masterpage/MyPathtoJavascriptFile/mycustomjavascriptfile.js” runat=”server” OnDemand=”false” LoadAfterUI=”true” Localizable=”false”/>