一、提交的内容在当前页面中处理,防止刷新当前页面再次提交
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        AdoSql AddComent = new AdoSql();
        AddComent.Add_Input_Coment(this.GetNewsID(), this.TextBox3.Text, this.TextBox1.Text, this.TextBox2.Text);
        //防止刷新页面时候的回发问题
        int iResult;
        int iUp = 1000;
        Random ro = new Random();
        iResult = ro.Next(iUp);
        string url = "read_news.aspx?n_);
        }

}

2、
//页面加载
protected void Page_Load(object sender, EventArgs e)
{
   //可以在页面加载时设置页面的缓存为“SetNoStore()”,即无缓存
   Response.Cache.SetNoStore();
   //Session中存储的变量“IsSubmit”是标记是否提交成功的
   if ((bool)Session["IsSubmit"])
   {
     //如果表单数据提交成功,就设“Session["IsSubmit"]”为false
     Session["IsSubmit"] = false;
     //显示提交成功信息
     ShowMsg.Text = " * 提交成功!";
   }
   else
     //否则的话(没有提交,或者是页面刷新),不显示任何信息
     ShowMsg.Text = "";
}
//提交按钮(btnOK)单击事件
protected void btnOK_Click(object sender, EventArgs e)
{
   if (txtTitle.Text.ToString().Trim() == "") ........
     else if (txtText.Text.ToString().Trim() == "") .......
      else
   {
     //这里是将数据提交到数据库中,省略
     /*
     string sql = "insert into tab...values(...)";
     MyConn.ExecQuery(sql);
     */
     //提交成功后,设“Session["IsSubmit"]”为true
     Session["IsSubmit"] = true;
     //强制转换页面(不可少,否则刷新仍会重复提交,仍转到本页),
     //通过页面的转换将缓存中的提交的数据都释放了,即提交的标单数据不会被保存到缓存里,
    // 如果后退的话,将会出现该页无法显示
     Response.Redirect("post.aspx");
  }
}

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2021-10-21
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
猜你喜欢
  • 2022-03-01
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2021-09-17
相关资源
相似解决方案