我們經常在首頁中要瀏覽分類資訊,在C/S模式下,經常採用Tab分頁的方式來做,然後將不同的資訊放到不同的Tab頁中,然後可以點擊頁簽去查看不同頁面中的內容。我們可以用網頁的IFRAME來實行這個功能,先建立一個主WebForm1,在上面放兩個按鈕來類比頁簽(今後也可以用Photoshop來製作更精美的頁簽),然後再建立兩個子Form,WebForm2,WebForm3,當按鈕被按下的時候來切換IFRAME的src屬性去顯示不同的子頁面。具體代碼如下:
WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="iframetest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<STYLE>.aaa {
BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #ffcc33; BORDER-BOTTOM-STYLE: none
}
.bbb {
BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #99ffcc; BORDER-BOTTOM-STYLE: none
}
</STYLE>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:button id="Button1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server"
Text="Button" CssClass="aaa"></asp:button>
<asp:Button id="Button2" style="Z-INDEX: 102; LEFT: 72px; POSITION: absolute; TOP: 24px" runat="server"
Text="Button" CssClass="bbb"></asp:Button>
<iframe id="IFRAME1" style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; Z-INDEX: 103; LEFT: 16px; BORDER-LEFT: 0px solid; WIDTH: 648px; BORDER-BOTTOM: 0px solid; POSITION: absolute; TOP: 40px; HEIGHT: 288px"
runat="server"></iframe>
</form>
</body>
</HTML> |
WebForm1.aspx.cs
.
.
. private void Button1_Click(object sender, System.EventArgs e)
{
IFRAME1.Attributes.Add("src","Webform2.aspx");
} private void Button2_Click(object sender, System.EventArgs e)
{
IFRAME1.Attributes.Add("src","Webform3.aspx");
} |