C#控制Css样式

by benben 5/14/2008 10:25:39 PM

今天需要动态修改前台Css样式,也懒得用javascript,发现只要在标签里加上runat ="server",即可在后台控制样式。

前台代码为:

<div runat ="server" id="show">我的ID为show</div>
<div runat="server"  id="hide">我的ID为hide</div>
<asp:Button ID="btnShow" runat="server" Text="Show" onclick="Show_Click" />   
<asp:Button ID="btnHide" runat="server" Text="Hide" onclick="Hide_Click" />     

后台代码为:

    protected void Show_Click(object sender, EventArgs e)
    {
        show.Style.Add("display", "none");
        hide.Style.Clear();
    }
    protected void Hide_Click(object sender, EventArgs e)
    {
        hide.Style.Add("display", "none");
        show.Style.Clear();
    }
}

即可动态控制div的显示了,详细见测试文件。File icon雷击下载div-test.zip

test

Tags: , , ,

.net

Add comment

 

   

 

  Country flag

buquote
Loading

Powered by BlogEngine.NET 苏ICP备08023017号



Recent comments

Author

声明

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in