如何更新和重定向到以前的页面使用javascript

How do update and redirect to previous page using javascript

本文关键字:javascript 何更新 更新 重定向      更新时间:2023-09-26

我有一个可以添加评论的新闻页面。如果我点击一个评论,我会进入一个评论页面,在那里我可以选择删除评论。如果我删除了评论,我想回到新闻页面并刷新页面,以便评论消失。

我尝试添加这个,但是没有到达删除函数

<asp:Button runat="server" ID="btnRemoveComment" Text="Ta bort" OnClientClick="JavaScript: window.history.back(1); return false;" />

Commentpage.aspx

<asp:Button runat="server" ID="btnRemoveComment" />

Commentpage.aspx.cs

protected override void OnLoad(EventArgs e)
{
  btnRemoveComment.Click += btnRemoveComment_Click;
}

private void btnRemoveComment_Click(object sender, EventArgs e)
{
  CommentFactory.RemoveComment(CurrentPage);
}

一个按钮不能应用两个事件,这是javascript或代码隐藏。尝试在代码后重定向并使用Ajax进行动态更新。

我认为在新闻页和评论页之间来回切换是不好的。试试这个

private void btnRemoveComment_Click(object sender, EventArgs e)
{
  CommentFactory.RemoveComment(CurrentPage);
  Response.Redirect("news.aspx");
}