asp.net background dynamic add JS file and css file reference implementation method

  • 2021-01-14 05:48:11
  • OfStack

In this paper, the example tells the asp.net background dynamic add JS file and css file reference implementation method. Share with you for your reference. The specific methods are as follows:

First add the namespace


using System.Web.UI.HtmlControls;

The code dynamically adds references to css files:


HtmlGenericControl myCss = new HtmlGenericControl();
myCss .TagName = "link";
myCss .Attributes.Add("type", "text/css");
myCss .Attributes.Add("rel", "stylesheet");
myCss .Attributes.Add("href", ResolveUrl(Page.ResolveClientUrl("css The file path ")));
this.Page.Header.Controls.AddAt(0, myCss );

The code dynamically adds references to JS files:


HtmlGenericControl myJs = new HtmlGenericControl();
myJs .TagName = "script";
myJs .Attributes.Add("type", "text/javascript");
myJs .Attributes.Add("src", ResolveUrl(Page.ResolveClientUrl("js The file path ")));
this.Page.Header.Controls.AddAt(1, myJs );

The approach described in this article is simple. Here is a record of 1, I hope this article is helpful to you asp.net program design.


Related articles: