不用Asp.net Ajax ControlToolKit中的Tabs控件实现Tabs效果的简单实现方法:
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>
\n
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Tabs</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<fieldset>
<legend>
<asp:Button ID=”btnView1″ runat=”server” Text=”显示View1″ BackColor=”ControlLight” onClick=”btnView1_Click” />
<asp:Button ID=”btnView2″ runat=”server” Text=”显示View2″ BackColor=”ControlLight” onClick=”btnView2_Click” />
<asp:Button ID=”btnView3″ runat=”server” Text=”显示View3″ BackColor=”ControlLight” onClick=”btnView3_Click” />
</legend>
<asp:MultiView ID=”MultiView1″ runat=”server” OnActiveViewChanged=”MultiView1_ActiveViewChanged”>
<asp:View ID=”View1″ runat=”server”>
<span style=”color: background”>这是View1!</span></asp:View>
<asp:View ID=”View2″ runat=”server”>
<span style=”color: #ff66cc”>这是View2!</span></asp:View>
<asp:View ID=”View3″ runat=”server”>
<span style=”color: darkolivegreen”>这是View3!</span></asp:View>
</asp:MultiView></fieldset>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
\n
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MultiView1.ActiveViewIndex = 0;
}
}
protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
{
switch (MultiView1.ActiveViewIndex)
{
case 0:
btnView1.BorderStyle = BorderStyle.Inset;
btnView2.BorderStyle = BorderStyle.NotSet;
btnView3.BorderStyle = BorderStyle.NotSet;
break;
case 1:
btnView2.BorderStyle = BorderStyle.Inset;
btnView1.BorderStyle = BorderStyle.NotSet;
btnView3.BorderStyle = BorderStyle.NotSet;
break;
case 2:
btnView3.BorderStyle = BorderStyle.Inset;
btnView1.BorderStyle = BorderStyle.NotSet;
btnView2.BorderStyle = BorderStyle.NotSet;
break;
}
}
protected void btnView1_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 0;
}
protected void btnView2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 1;
}
protected void btnView3_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 2;
}
}
演示图片:
\n
\n
来源:cnblogs