执行以下代码时如果刷新CLICK事件会再次执行!!!请问如何避免网页刷新时再次提交数据呢?谢谢~~ ·_·
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.Write("第一次\n");
Session["b"] = "a";
}
else
{
Response.Write("第二次");
} }
bool flag = false;
protected void Button1_Click(object sender, EventArgs e)
{
Session["b"] += "提交一次"; Response.Write(Session["b"].ToString()); flag = true;
Show();
flag = false;
}
protected void Show()
{
if (flag)
{
//Response.Write("操作一次数据库");
Session["b"] += "插入一次";
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.Write("第一次\n");
Session["b"] = "a";
}
else
{
Response.Write("第二次");
} }
bool flag = false;
protected void Button1_Click(object sender, EventArgs e)
{
Session["b"] += "提交一次"; Response.Write(Session["b"].ToString()); flag = true;
Show();
flag = false;
}
protected void Show()
{
if (flag)
{
//Response.Write("操作一次数据库");
Session["b"] += "插入一次";
}
}
2. 执行完click事件处理后,用redirect到本页面
response.redirect()
{
if (!IsPostBack)
{
Response.Write("第一次\n");
Session["b"] = "a";
}
else
{
Response.Write("第二次");
}
}
/// <summary>
/// 提交
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
Session["b"] += "提交一次";
Show();
Response.Write(Session["b"].ToString());
Response.Redirect("MainPage.aspx");
}
protected void Show()
{
string str = File.ReadAllLines(@"F:\TestFile.txt")[0];
int sss = Convert.ToInt32(str) + 1;
File.WriteAllText(@"F:\TestFile.txt", sss.ToString());
}