很简单,后台得到一个随机数a,保存到session中,页面上弄个隐藏值b,每次执行数据操作时,比较 a==b(true执行操作),自己在网上找的代码已经测试通过
哪位大虾有更好的解决方案不妨指点下啊。本人菜鸟一个
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%#Eval("zname") %><br />
</ItemTemplate>
</asp:Repeater>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="SubmitButton" runat="server" Text="Button" OnClientClick="return check()" onclick="Button1_Click" />
cs:文件
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bindrpt();
if (RefreshID.Text.Length == 0)
{
RefreshID.Text = Session.SessionID + DateTime.Now.Ticks.ToString();
}
}
}
public void Bindrpt()
{
DataSet ds = new Reworld.BLL.tb_Zui().GetList(10, "", "id desc");
this.Repeater1.DataSource = ds.Tables[0];
this.Repeater1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string sesToken = (string)Session["FrameworkConst.SYNC_CONTROL_KEYWORD"];
string pageToken = RefreshID.Text;
Label1.Text = sesToken;
if (sesToken == null || sesToken == pageToken)//执行数据操作
{
Label2.Text = "true";
string zname = this.TextBox1.Text;
Reworld.Model.tb_Zui model = new Reworld.Model.tb_Zui();
model.ZName = zname;
new Reworld.BLL.tb_Zui().Add(model);
TextBox1.Text = DateTime.Now.Ticks.ToString();
Bindrpt();
Response.Write("The Refresh was performed after submit.");
}
else
{
Label2.Text = "false";
// do your processing here to avoid Refresh trap
Response.Write("The processing is done here. Disabling submitbutton so that user can not perform multiple submit.");
Response.Write("But still user can peform Refresh on page.");
}
string st = Session.SessionID + DateTime.Now.Ticks.ToString();
Session["FrameworkConst.SYNC_CONTROL_KEYWORD"] = st;
RefreshID.Text = st;
}