zoukankan      html  css  js  c++  java
  • ASP.NET以编程的方式动态的添加Css引用

    使用的类 HtmlLink

    HtmlLink类的作用是:以编程的方式访问服务器上的html元素

    注意:head必须为服务器控件 ,即 <head id="head1" runat="server">

    <%@ Page Language="C#"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
    
      protected void Page_Init(object sender, EventArgs e)
      {
        // Define an HtmlLink control.
        HtmlLink myHtmlLink = new HtmlLink();
        myHtmlLink.Href = "~/StyleSheet.css";
        myHtmlLink.Attributes.Add("rel", "stylesheet");
        myHtmlLink.Attributes.Add("type", "text/css");
        
        // Add the HtmlLink to the Head section of the page.
        Page.Header.Controls.Add(myHtmlLink);//将动态生成的css添加到head中
        
      }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
      <head id="head1" 
            runat="server">
        <title>HtmlLink Example Page</title>
      </head>
      <body>
        <form id="form1" 
              runat="server">
          <h1>HtmlLink Example Page</h1>
          This is some text in the body of the Web Forms page.
        </form>
      </body>
    </html>
    

    详细信息请参考MSDN   http://msdn.microsoft.com/zh-cn/library/system.web.ui.htmlcontrols.htmllink(v=VS.85).aspx

  • 相关阅读:
    php流程控制
    php运算符
    php数据类型
    php基础
    谈谈2019年
    聊聊这三年
    第二次作业(源代码)
    个人介绍
    22.python匿名函数详解
    11.python内置模块之json模块
  • 原文地址:https://www.cnblogs.com/luodao1991/p/3012463.html
Copyright © 2011-2022 走看看