WebForm 專案中使用 JQuery Mobile 有時希望在一個程式頁面下 .aspx 將不同頁面寫在一起,一來避免程式頁面越來越多,另外維護相關程式碼也較方便,之前透過 CSS display 隱藏其它頁面元件,程式中常要判斷何時要顯示又何時隱藏,好不累人。之前知道 Pages 可用於多個頁面,但在 ASP.NET 下始終沒有找到解決的方法。好在最後仍不負眾望(其實只有我本人)試出下列方法,令人感動 T _ T,那就趕快記下來吧..
在 Site.Master.aspx 頁面中加入兩個頁面(FirstPage & SecondPage)
<body>
<div data-role="page" id="FirstPage">
<form runat="server">
<asp:ScriptManager runat="server">
<Scripts>
...
</Scripts>
</asp:ScriptManager>
<head id="hd" ... >
...
</head>
<div class="container body-content ui-content" data-role="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer id="ft" ... >
</footer>
<div data-role="page" id="SecondPage">
<form runat="server">
<asp:ScriptManager runat="server">
<Scripts>
...
</Scripts>
</asp:ScriptManager>
<head id="hd2" ... >
...
</head>
<div class="container body-content ui-content" data-role="main">
<asp:ContentPlaceHolder ID="MainContent2" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer id="ft2" ... >
</footer>
</body>
在要寫入多個頁面的 aspx 中加入 Content (ID要同 Site.Master 中頁面所定義的哦)
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="TestFunction.aspx.cs" Inherits="HonSec.AP.eTradeWebMobileSoltion.MapServerPos" %>
...
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<p><a href="#SecondPage">Here is the First Page ^ ^ </a></p>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent2" runat="server">
<p><a href="#FirstPage">Here is the Second Page ^ ^ </a></p>
</asp:Content>
在 Site.Master.aspx 頁面中加入兩個頁面(FirstPage & SecondPage)
<body>
<div data-role="page" id="FirstPage">
<form runat="server">
<asp:ScriptManager runat="server">
<Scripts>
...
</Scripts>
</asp:ScriptManager>
<head id="hd" ... >
...
</head>
<div class="container body-content ui-content" data-role="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer id="ft" ... >
</footer>
<div data-role="page" id="SecondPage">
<form runat="server">
<asp:ScriptManager runat="server">
<Scripts>
...
</Scripts>
</asp:ScriptManager>
<head id="hd2" ... >
...
</head>
<div class="container body-content ui-content" data-role="main">
<asp:ContentPlaceHolder ID="MainContent2" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer id="ft2" ... >
</footer>
</body>
在要寫入多個頁面的 aspx 中加入 Content (ID要同 Site.Master 中頁面所定義的哦)
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="TestFunction.aspx.cs" Inherits="HonSec.AP.eTradeWebMobileSoltion.MapServerPos" %>
...
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<p><a href="#SecondPage">Here is the First Page ^ ^ </a></p>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent2" runat="server">
<p><a href="#FirstPage">Here is the Second Page ^ ^ </a></p>
</asp:Content>
留言
張貼留言