protected override void CreateChildControls() { base.CreateChildControls(); // Add CSS file to page header string cssUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "MyWebPart.MyStyles.css"); LiteralControl cssLink = new LiteralControl(string.Format("", cssUrl)); Page.Header.Controls.Add(cssLink); }
protected override void CreateChildControls() { base.CreateChildControls(); // Add external JavaScript file to web part string jsUrl = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"; ScriptLink.Register(this.Page, jsUrl, false); }In this example, the ScriptLink.Register method is used to add an external JavaScript file to the web part. The first parameter indicates the page where the script will be added, the second parameter is the URL of the script to add, and the third parameter specifies that the script should not be inserted in the page header. Package Library: This example code belongs to the Microsoft.SharePoint.WebControls namespace, which is part of the Microsoft.SharePoint.Client.dll library used in SharePoint development.