---
title: "C# Tab"
author: "K10692081"
date: "2012-06-06T00:25:51Z"
tags: []
categories: ["非技术"]
slug: "c-tab"
draft: false
lastmod: "2012-06-06T00:25:51Z"
id: 1552726
url: "https://k10692081.iteye.com/blog/1552726"
---

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;  
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;  
&lt;head id="Head1" runat="server"&gt;  
    &lt;title&gt;Tab后台CS程序实现&lt;/title&gt;  
    &lt;style type="text/css"&gt;  
        body  
        {  
            color: #000000;  
            background-color: #ffffff;  
            font-family: Tahoma, 宋体;  
            font-size: 12px;  
            margin: 0px;  
            padding: 0px;  
            text-align: center;  
        }  
        #TabButton1, #TabButton2, #TabButton3  
        {  
            margin-top: 20px;  
            width: 60px;  
        }  
        .aaa  
        {  
            background-color: #E0E0E0;  
        }  
        .bbb  
        {  
            background-color: Gray;  
            color: White;  
        }  
        #tab1, #tab2, #tab3  
        {  
            width: 188px;  
            height: 100px;  
            background-color: #E0E0E0;  
            overflow: auto;  
        }  
        #tab2, #tab3  
        {  
            display: none;  
        }  
    &lt;/style&gt;  
&lt;/head&gt;  
&lt;body&gt;  
    &lt;form id="form1" runat="Server"&gt;  
    &lt;center&gt;  
        &lt;div&gt;  
            &lt;asp:Button ID="TabButton1" runat="server" CssClass="aaa" Text="查询" OnClick="TabButton1\_Click" /&gt;  
            &lt;asp:Button ID="TabButton2" runat="server" CssClass="bbb" Text="新建" OnClick="TabButton2\_Click" /&gt;  
            &lt;asp:Button ID="TabButton3" runat="server" CssClass="bbb" Text="修改" OnClick="TabButton3\_Click" /&gt;  
        &lt;/div&gt;  
        &lt;div id="tab1" runat="Server"&gt;  
            &lt;asp:Label ID="Label1" runat="server" Text="111-查询"&gt;&lt;/asp:Label&gt;  
        &lt;/div&gt;  
        &lt;div id="tab2" runat="Server"&gt;  
            &lt;asp:Label ID="Label2" runat="server" Text="222-新建"&gt;&lt;/asp:Label&gt;  
        &lt;/div&gt;  
        &lt;div id="tab3" runat="Server"&gt;  
            &lt;asp:Label ID="Label3" runat="server" Text="333-修改"&gt;&lt;/asp:Label&gt;  
        &lt;/div&gt;  
    &lt;/center&gt;  
    &lt;/form&gt;  
&lt;/body&gt;  
&lt;/html&gt;

 

C#:

 

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;

namespace JavascriptTest01  
{  
    public partial class WebForm5 : System.Web.UI.Page  
    {  
        protected void Page\_Load(object sender, EventArgs e)  
        {

        }  
        protected void TabButton1\_Click(object sender, EventArgs e)  
        {  
            tab1.Style.Add("display", "block");  
            tab2.Style.Add("display", "none");  
            tab3.Style.Add("display", "none");  
            TabButton1.CssClass = "aaa";  
            TabButton2.CssClass = "bbb";  
            TabButton3.CssClass = "bbb";  
        }  
        protected void TabButton2\_Click(object sender, EventArgs e)  
        {  
            tab1.Style.Add("display", "none");  
            tab2.Style.Add("display", "block");  
            tab3.Style.Add("display", "none");  
            TabButton1.CssClass = "bbb";  
            TabButton2.CssClass = "aaa";  
            TabButton3.CssClass = "bbb";  
        }  
        protected void TabButton3\_Click(object sender, EventArgs e)  
        {  
            tab1.Style.Add("display", "none");  
            tab2.Style.Add("display", "none");  
            tab3.Style.Add("display", "block");  
            TabButton1.CssClass = "bbb";  
            TabButton2.CssClass = "bbb";  
            TabButton3.CssClass = "aaa";  
        }  
    }  
}