星期五, 11月 28, 2008

解決重複新增問題..

剛剛逛網站..逛到我好朋友的blog..裡面有一篇文章"避免因重新整理導致的重複新增問題"..看到他的作法..我也把我的作法提供一下..首先我會模擬兩個測試頁..test.aspx(填寫頁)..test1.aspx(結果頁)..看code說故事ㄅ..

test.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</form>
</body>
</html>

test.cs

using System;
using System.Web;

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.MinValue);
}
protected void Button1_Click(object sender, EventArgs e)
{
//這裡寫你要寫的code
Server.Transfer("~/test1.aspx", true);
}
}

test1.aspx

<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
填寫內容:<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</div>
</form>
</body>
</html>

test1.cs

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
Literal1.Text = (Page.PreviousPage.FindControl("TextBox1") as TextBox).Text;
}
}

這樣流程合理..按前一頁也不會出現之前所填的資料內容..參考一下ㄅ..DevilDevilDevilDevilDevilDevilDevilDevilDevilDevilDevil..

參考:
http://demo.tc/view.aspx?id=410
http://bibby.be/2008/04/cache.html

http://msdn.microsoft.com/en-us/library/ms525800.aspx

沒有留言: