protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ViewState["BackUrl"] = Request.UrlReferrer.ToString();
    }
}

/// <summary>
/// 返回按钮点击事件
/// </summary>
protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect(ViewState["BackUrl"].ToString());
}

另一种方法

在C# Web程序中,如为页面按钮写返回上一页代码

this.RegisterClientScriptBlock("E", "<script language=javascript>history.go(-2);</script>");

其中,history.go(-2),要写为-2,因在按钮事件触发前,已刷新一次页面,所以应是-2。

Response.Write("<script language=javascript>history.go(-2);</script>");

此处也要写为“-2”。跟直接写脚本的有所不同。

 

来自:http://www.zhisi.net/a/08/05-21/9920.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-12-05
  • 2021-06-10
  • 2021-08-18
猜你喜欢
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2022-12-23
  • 2021-10-17
相关资源
相似解决方案