ASP. NET instance code Tutorial: dynamically Switch CSS styles

Source: Internet
Author: User

Asp.net documentThe following is the instance code. Webmasters can try it on their own.:

  1. Using System;
  2. Using System. Data;
  3. Using System. Configuration;
  4. Using System. Web;
  5. Using System. Web. Security;
  6. Using System. Web. UI;
  7. Using System. Web. UI. WebControls;
  8. Using System. Web. UI. WebControls. WebParts;
  9. Using System. Web. UI. HtmlControls;
  10. /// <Summary>
  11. /// CSSService service class
  12. /// </Summary>
  13. Public class CSSService
  14. {
  15. Public CSSService ()
  16. {
  17. //
  18. // TODO: add the constructor logic here
  19. //
  20. }
  21. # Region Switch CSS
  22. /// <Summary>
  23. /// Switch CSS
  24. /// Author: Hu Hai
  25. /// Date:
  26. /// </Summary>
  27. /// <Param name = "page"> current Page </param>
  28. /// <Param name = "CSSFilePath"> relative address of the CSS file to the website root directory </param>
  29. Public static void SwitchCSS (Page page, string CSSFilePath)
  30. {
  31. HtmlLink link = new HtmlLink ();
  32. Link. Href = CSSFilePath;
  33. Link. Attributes ["rel"] = "stylesheet ";
  34. Link. Attributes ["type"] = "text/css ";
  35. Page. Header. Controls. Add (link );
  36. }
  37. # Endregion
  38. }

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.