Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to add references to JS files and css files dynamically in the background by asp.net

Shulou Source: shulou.com Published: 2022-05-31 13:17:46 09月10日 Update

In this article Xiaobian introduces in detail for you "asp.net how to dynamically add references to JS files and css files in the background" with detailed contents, clear steps and proper handling of details. I hope that this article "asp.net how to dynamically add JS files and references to css files in the background" can help you solve your doubts.

First add a namespace

Using System.Web.UI.HtmlControls

The code dynamically adds a reference to the css file:

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

The code dynamically adds a reference to the JS file:

HtmlGenericControl myJs = new HtmlGenericControl (); myJs .TagName = "script"; myJs .Attributes.Add ("type", "text/javascript"); myJs .Attributes.Add ("src", ResolveUrl ("js file path")); this.Page.Header.Controls.AddAt (1, myJs) Read this, the "asp.net how to dynamically add JS files and css file references" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, welcome to pay attention to the industry information channel.

Tags: Documents dynamic background articles code content paths proper ideas new knowledge more steps knowledge knowledge points space articles details industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB OPPO Reno NVidia Apple