Asp.net documentThe following is the instance code. Webmasters can try it on their own.:
- Using System;
- Using System. Data;
- Using System. Configuration;
- Using System. Web;
- Using System. Web. Security;
- Using System. Web. UI;
- Using System. Web. UI. WebControls;
- Using System. Web. UI. WebControls. WebParts;
- Using System. Web. UI. HtmlControls;
- /// <Summary>
- /// CSSService service class
- /// </Summary>
- Public class CSSService
- {
- Public CSSService ()
- {
- //
- // TODO: add the constructor logic here
- //
- }
- # Region Switch CSS
- /// <Summary>
- /// Switch CSS
- /// Author: Hu Hai
- /// Date:
- /// </Summary>
- /// <Param name = "page"> current Page </param>
- /// <Param name = "CSSFilePath"> relative address of the CSS file to the website root directory </param>
- Public static void SwitchCSS (Page page, string CSSFilePath)
- {
- HtmlLink link = new HtmlLink ();
- Link. Href = CSSFilePath;
- Link. Attributes ["rel"] = "stylesheet ";
- Link. Attributes ["type"] = "text/css ";
- Page. Header. Controls. Add (link );
- }
- # Endregion
- }
|
The call code is as follows:
| CSSService. SwitchCSS (Page, Common. CSSFilePath ); |
Note: The class is used in CSS to control the expression of elements. Otherwise, CSS will not take effect.