日期:2014-05-17 浏览次数:20391 次
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(); } } }
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>");