并非原创,原帖地址:http://hi.baidu.com/djcm99/blog/item/4340ad00c25cd216738b65c5.html
test.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!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>test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:HiddenField ID="HidSign" runat="server" />
</div>
</form>
</body>
</html>
test.aspx.cs
using System;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UpdateSign();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["HidSign"].ToString() == HidSign.Value)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "startup", "alert('更新成功!')", true);
UpdateSign();
}
else
{
this.ClientScript.RegisterStartupScript(this.GetType(), "startup", "alert('请勿重复提交!');", true);
UpdateSign();
}
}
private void UpdateSign()
{
HidSign.Value = DateTime.Now.ToString("ffffff");
Session["HidSign"] = HidSign.Value;
}
}