CSS 使用主版頁面的內容頁如何調用css和javascript

來源:互聯網
上載者:User

標籤:

方案一:

  把所有的css樣式和javascript函數放到主版頁面的<head></head>中,我覺得這樣做的弊端就是導致主版頁面的<head></head>區特別臃腫,同時如果原來兩個頻道頁中包含同名的css聲明或javascript函數,但卻是不同樣式或執行不同操作。

 

方案二:

  在內容頁的PageLoad事件中通過代碼來指定本內容頁的css檔案。

代碼如下

static public class ControlHelper 

  static public void AddStyleSheet(Page page, string cssPath) 
  { 
    HtmlLink link = new HtmlLink(); 
    link.Href = cssPath; 
    link.Attributes["rel"] = "stylesheet"; 
    link.Attributes["type"] = "text/css"; 
    page.Header.Controls.Add(link); 
  } 

  在具體頁面,我們就可以通過如下代碼添加 CSS 引用: 

protected void Page_Load(object sender, EventArgs e)
{
  ControlHelper.AddStyleSheet(this.Page, "css/projectPage.css");
}

  這種解決方案的好處時可以在程式運行時動態更改所需的css檔案,但是對javascript函數處理起來該怎麼做呢?再說有必要把本該加在html代碼中的css和javascript通過cs代碼來加入嗎?

 

方案三:

  在主版頁面的<head></head>中添加一個ContentPlaceHolder控制項,然後在內容頁中在對應的內容控制項中寫css和javascript代碼。

 

CSS 使用主版頁面的內容頁如何調用css和javascript

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.