模板頁面
<!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>
<title>企業堂 - ASP.NET產生靜態頁技術</title>
<style type="text/css">
body{background:#62A6CD; color:#fff; font-size:14px; font-family:Verdana; line-height:20px;}
h1{line-height:35px;}
td{padding-left:5px;}
</style>
</head>
<body>
<h1>靜態主表頁</h1>
<table cellpadding="0" cellspacing="1" style="width:200px; background:#666; color:#333;" >
<tr>
<td style="width:30px; color:#fff">ID</td>
<td style="width:170px; color:#fff">Name</td>
</tr>
<!--Repeat{select * from Test}-->
<tr style="line-height:26px; background:#fff;">
<td>{Id}</td>
<td><a href="StaticDetail_{Id}.htm" target="_blank">{Name}</a></td>
</tr>
<!--RepeatEnd-->
</table>
</body>
</html>
web.config檔案
<?xml version="1.0" encoding="utf-8"?>
<!--
注意: 除了手動編輯此檔案以外,您還可以使用
Web 管理工具來配置應用程式的設定。可以使用 Visual Studio 中的
“網站”->“Asp.Net 配置”選項。
設定和注釋的完整列表在
machine.config.comments 中,該檔案通常位於
WindowsMicrosoft.NetFrameworkv2.xConfig 中
-->
<configuration>
<appSettings/>
<connectionStrings>
<add name="QYTangConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Test.mdb" providerName="System.Data.OleDb" />
</connectionStrings>
<system.web>
<!--
設定 compilation debug="true" 將偵錯符號插入
已編譯的頁面中。但由於這會
影響效能,因此只在開發過程中將此值
設定為 true。
-->
<compilation debug="false" />
<!--
通過 <authentication> 節可以配置 ASP.NET 使用的
安全身分識別驗證模式,
以標識傳入的使用者。
-->
<authentication mode="Windows" />
<!--
如果在執行請求的過程中出現未處理的錯誤,
則通過 <customErrors> 節可以配置相應的處理步驟。具體說來,
開發人員通過該節可以配置
要顯示的 html 錯誤頁
以代替錯誤堆疊追蹤。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
index.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;
using QYTang.Gengerate;
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
DateTime dt = DateTime.Now;
Gengerate g = new Gengerate();
g.GengerateHtml();
DateTime dt2 = DateTime.Now;
TimeSpan ts = dt2.Subtract(dt);
string strTs = ts.TotalSeconds.ToString();
ltGengerate.Text = "產生成功,產生用時" + strTs + "秒!";
}
catch (Exception ex)
{
throw ex;
}
}
}
index.aspx檔案
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
<!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>- ASP.NET產生靜態頁技術</title>
<style type="text/css">
body{background:#62A6CD; color:#fff; font-size:14px; font-family:Verdana; line-height:20px;}
input{line-height:20px;}
</style>
</head>
<body>
<form id="form1" runat="server">
友情提醒:開啟靜態首頁前,請先產生靜態頁。<br /><br />
<input id="btnStatic" type="button" value="開啟靜態主表頁" /> <asp:Button ID="btnSubmit" runat="server" Text=" 產生靜態頁 " OnClick="btnSubmit_Click" /> <asp:Literal ID="ltGengerate" runat="server"></asp:Literal>
</form>
<script type="text/javascript">
var btnStatic=document.getElementById("btnStatic");
btnStatic.onclick=function(){ window.open("StaticMain.htm") }
</script>
</body>
</html>