日期:2014-05-17  浏览次数:20391 次

评论完,每次刷新页面,都会弹出 "评论成功!" 评论条数也增加了.
有两个问题:

1,评论成功之后,清空了编辑框, 然后刷新页面,竟然还会弹出"评论成功!" 评论数目也增加了.

2, 评论完成之后, 顺便刷新页面,怎么弄?



C# code
 
       protected void Reply_Click(object sender, EventArgs e)
        {


                if (ReplyBox.Text.Trim() == "")
                {
                    Response.Write("<script language=javascript>alert('评论内容不能为空!');location='javascript:history.go(-1)'</script>");
                    Response.End();
                }
                else
                {
                    try
                    {
                        if (cn.State == System.Data.ConnectionState.Closed)
                        {
                            cn.Open();
                        }
                        string reply_sql = "insert into reply (content,id,date) values ('" + ReplyBox.Text + "','" + Request.QueryString["id"] + "','" + DateTime.Now.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss") + "')";
                        SqlCommand com_r = new SqlCommand(reply_sql, cn);
                        com_r.ExecuteNonQuery();
                        Response.Write("<script language=javascript>alert('评论成功!');</script>");
                        ReplyBox.Text = "";
                    }
                    catch
                    {
                        Response.Write("<script language=javascript>alert('评论失败!');location='javascript:history.go(-1)'</script>");
                    }
                    finally
                    {
                        cn.Close();
                    }
                }

        }


------解决方案--------------------
评论成功之后,直接重新加载本页面,这样就不会啦,要不然你刷新页面时,会记录一些状态
------解决方案--------------------
C# code
            Response.Clear();
            string script = "<script>alert('添加成功!'); location.href='" + Request.RawUrl + "'</script>";
            Response.Write(script);
            Response.End();

------解决方案--------------------
Response.Write(“<script>location.href=‘’</script>”) 提交本页面不就行了…… 真复杂。
------解决方案--------------------
Response.Write("<script language=javascript>alert('评论成功!');location.href=location.href</script>");