動態改變頁面的CSS樣式

來源:互聯網
上載者:User

在asp.net中,有的時候要動態變換CSS,比如有的時候做個人化頁面,可以這樣做
<head>
<link id="MyStyleSheet" rel="stylesheet" type="text/css" runat="server" />
</head>
之後,在要更換CSS的頁面中,使用如下代碼
Sub Page_Load(Sender As Object, E As EventArgs)
 If Not (IsPostBack)
  MyStyleSheet.Attributes.Add("href","/css/flostyle.css")
 End If
End Sub

看到網上一位網友問 如何在C# 中設定

下面這個一定要放到<head></head>之間
//<link id="css1" type="text/css" runat="server" rel="stylesheet" />

在.cs檔案中定義
protected System.Web.UI.HtmlControls.HtmlGenericControl  css1;

在Page_load中寫
css1.Attributes.Add("href","/css/flostyle.css")
就能自訂風格了!

相關文章

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.