How can I dynamically Add references to JS files and css files in the asp.net background?
First, add the namespace using System. Web. UI. HtmlControls;
1. add reference to css files dynamically in the code
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 file path ")));
This. Page. Header. Controls. AddAt (0, myCss );
2. dynamically Add references to JS files in the code
HtmlGenericControl myJs = new HtmlGenericControl ();
MyJs. TagName = "script ";
MyJs. Attributes. Add ("type", "text/javascript ");
MyJs. Attributes. Add ("src", ResolveUrl (Page. ResolveClientUrl ("js file path ")));
This. Page. Header. Controls. AddAt (1, myJs );
This is a simple method. Record it here.