Separately, the file will not work, since it does not expand on the SharePoint server. You must use the module: In the right place of the project (be it the root or other project folder), right-click on "Add" -> "Office / SharePoint" -> "Module ". We clean everything up there, then we add the necessary file, in my case it is JavaScript1.js, the following XML is automatically created:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="ScriptPanelButton"> <File Path="ScriptPanelButton\JavaScript1.js" Url="ScriptPanelButton/JavaScript1.js" /> </Module> </Elements>
In general, with this we can already do something, but it is better to make changes:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="ScriptPanelButton" Url="Scripts/PanelButtonScripts"> <File Path="ScriptPanelButton\JavaScript1.js" Url="ScriptPanelButton/JavaScript1.js" /> </Module> </Elements>
Well, then in the code, when loading the panel:
protected override void OnLoad(EventArgs e) { base.OnLoad(e); string scriptPath = "Scripts/PanelButtonScripts/ScriptPanelButton/JavaScript1.js"; Page.ClientScript.RegisterClientScriptInclude(GetType(), "SHW", scriptPath); }
I note that a sub-site has been raised on our ball and the Scripts wiki library has been created in it, in which the script is unfolding. As a result, everything worked very well!
<script src=added, the js file was attached to the manifest, wrapped in a cab - that's all. Use exactly the same as in the usual html or aspx without SharePoint. - nick_n_a