Default2.aspx :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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>无标题页</title>
<script language="ecmascript" type="text/javascript">
function DisAppear(id)
{
document.getElementById("DelAttach").value=id;
document.forms[0].submit();
}
function ItemId(id)
{
document.getElementById("ItemID").value=id;
document.forms[0].submit();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="DelAttach" runat="Server" style="display: none" />
<input type="text" id="ItemID" runat="Server" style="display: none" />
<span id="LinkItems" runat="server">
<input id="ItemButton1" type="button" value="面板一" runat="server" onclick="javascript:ItemId('0')" style="cursor:hand;" /><br /><br />
<%-- <input id="ItemButton2" type="button" value="面板二" runat="server" onclick="javascript:ItemId('1')" />
<a href="javascript:DisAppear('2')"><img src='Del.jpg' alt="关闭" border=0></a>
<br /><br />--%>
</span>
<asp:Button ID="Button2" runat="server" Text="添加面板二" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="添加面板三" OnClick="Button3_Click" />
<asp:Button ID="Button4" runat="server" Text="添加面板四" OnClick="Button4_Click" />
<br /><br />
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="Tab1" runat="server">
<table width="600" height="400" cellpadding=0 cellspacing=0>
<tr valign="top">
<td class="TabArea" style="width: 600px">
面板一
</td>
</tr>
</table>
</asp:View>
<asp:View ID="Tab2" runat="server">
<table width="600" height="400" cellpadding=0 cellspacing=0>
<tr valign="top">
<td class="TabArea" style="width: 600px">
面板二
</td>
</tr>
</table>
</asp:View>
<asp:View ID="Tab3" runat="server">
<table width="600" height="400" cellpadding=0 cellspacing=0>
<tr valign="top">
<td class="TabArea" style="width: 600px">
面板三
</td>
</tr>
</table>
</asp:View>
<asp:View ID="Tab4" runat="server">
<table width="600" height="400" cellpadding=0 cellspacing=0>
<tr valign="top">
<td class="TabArea" style="width: 600px">
面板四
</td>
</tr>
</table>
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
Default2.aspx.cs :
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;
public partial class Default2 : System.Web.UI.Page
{
private static string sItems = "";//2◆3◆4
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
sItems = "";
DelLinkItems();
SetLinkItems();
}
protected void DelLinkItems()
{
string strID = DelAttach.Value.Trim();
if (strID != "")
{
sItems = LeaveItems(sItems, strID);
LinkItems.InnerHtml = "";
LinkItems.InnerHtml = GetHtmlItems(sItems);
}
DelAttach.Value = "";
}
protected string LeaveItems(string sItems, string sItem)
{
string[] sTemp;
string nItems = "";
sTemp = sItems.Split('◆');
for (int i = 0; i < sTemp.Length; i++)
{
if (sTemp[i].ToString() != sItem)
{
nItems += (nItems != "") ? "◆" + sTemp[i].ToString() : sTemp[i].ToString();
}
}
return nItems;
}
protected void SetLinkItems()
{
string strID = ItemID.Value.Trim();
if (strID != "")
{
MultiView1.ActiveViewIndex = Int32.Parse(ItemID.Value.ToString());
}
ItemID.Value = "";
}
protected string GetCommHtml()
{
string sHtml = "<input id=\"ItemButton1\" type=\"button\" ";
sHtml += "value=\"面板一\" runat=\"server\" style=\"cursor:hand;\" ";
sHtml += "onclick=\"javascript:ItemId('0')\" />";
return sHtml;
}
protected string GetSpecialHtml(string i, string sText)
{
string sI = Convert.ToString(Convert.ToUInt16(i) - 1);
string sHtml=" ";
sHtml += "<input type=\"button\" runat=\"server\" value=\"" + sText + "\" ";
sHtml += "ID=\"ItemButton" + i + "\" OnClick=\"javascript:ItemId('"+sI+"')\" ";
sHtml += "style=\"cursor:hand;\" ";
sHtml += "/>";
sHtml += "<a href=\"javascript:DisAppear('" + i + "')\">";
sHtml += "<img src='Del.jpg' alt=\"关闭\" border=0>";
sHtml += "</a>";
return sHtml;
}
protected bool IsShowItems(string sItems,string sItem)
{
if (sItems != "")
{
string[] sTemp;
sTemp = sItems.Split('◆');
for (int i = 0; i < sTemp.Length; i++)
{
if (sTemp[i].ToString() == sItem)
{
return true;
}
}
}
return false;
}
protected string GetHtmlItems(string sItems)
{
string[] sTemp;
string sHtml = GetCommHtml();
sTemp = sItems.Split('◆');
for (int i = 0; i < sTemp.Length; i++)
{
switch(sTemp[i].ToString())
{
case "1":
break;
case "2":
sHtml += GetSpecialHtml("2", "面板二");
break;
case "3":
sHtml += GetSpecialHtml("3", "面板三");
break;
case "4":
sHtml += GetSpecialHtml("4", "面板四");
break;
default:
break;
}
}
sHtml += "<br /><br />";
return sHtml;
}
protected void Button2_Click(object sender, EventArgs e)
{
//sItems += "◆2";
if (!IsShowItems(sItems,"2"))
sItems += (sItems != "") ? "◆2" : "2";
LinkItems.InnerHtml = "";
LinkItems.InnerHtml = GetHtmlItems(sItems);
}
protected void Button3_Click(object sender, EventArgs e)
{
//sItems += "◆3";
if (!IsShowItems(sItems, "3"))
sItems += (sItems != "") ? "◆3" : "3";
LinkItems.InnerHtml = "";
LinkItems.InnerHtml = GetHtmlItems(sItems);
}
protected void Button4_Click(object sender, EventArgs e)
{
if (!IsShowItems(sItems, "4"))
sItems += (sItems != "") ? "◆4" : "4";
LinkItems.InnerHtml = "";
LinkItems.InnerHtml = GetHtmlItems(sItems);
}
}