簡體   English   中英

使用C#代碼(ASP.net)選擇CSS樣式

[英]Choose CSS style using C# Code (ASP.net)

我的Default.aspx頁的嵌入式CSS中有兩個類。 如果需要,我可以將代碼傳輸到外部CSS。

我可以用C#編寫代碼嗎?在其中單擊按鈕后,可以在表格的兩種樣式之間進行選擇嗎? 我對ASP和C#非常陌生。

我的課程(嵌入式):

   .tftable
    {
        background-color: Blue;
        font-size: 12px;
        color: #333333;
        margin: 0px;
        padding: 0px;
        width: 100%;
        border-width: 1px;
        border-color: #729ea5;
        border-collapse: collapse;
    }

    .CSSTable
    {
        background-color: Gray;
        margin: 0px;
        padding: 0px;
        width: 100%; /*Fits the <div>*/
        box-shadow: 10px 10px 5px #888888;

    }

因此,單擊1按鈕后,我的表類將選擇“ tftable”,而另一個按鈕將選擇“ CSS”表類。

問候

它不是c#代碼,即javascript代碼

添加具有ID的樣式鏈接,如下所示

<link href="css/style1.css" type="text/css" rel="stylesheet" id="stylesheet" />

然后創建一個Javascript函數來更改Css文件

function changeStyle(name){
    if(name=='style1')
        document.getElementById('stylesheet').href='css/style1.css';
    else if(name=='style2')
        document.getElementById('stylesheet').href='css/style2.css';
    else if(name=='style3')
        document.getElementById('stylesheet').href='css/style3.css';
}

在您的按鈕中調用該功能

<ul>
<li><a href="javascript:changeStyle('style1')">Style1</a></li>
<li><a href="javascript:changeStyle('style2')">Style2</a></li>
<li><a href="javascript:changeStyle('style3')">Style3</a></li>
</ul>

參考

http://www.qualitycodes.com/tipdemos/javascript/dynamic-css/ http://www.qualitycodes.com/tip/14/dynamically-choosingchanging-a-css-file.html

希望您要對兩種樣式使用相同的css文件,如果是,請嘗試一次。

protected void Button1_Click(object sender, EventArgs e)
{
    myTable.Attributes.Add("class", "tftable");
}

protected void Button2_Click(object sender, EventArgs e)
{
    myTable.Attributes.Add("class", "CSSTable");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM