ASP.net(c#)返回上一页效果(后退)代码
. 方法1:单独使用,需要前台代码和后台代码
1.在后台my.aspx.cs装载函数中
void
Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack) //是首次装载,不是回发
{
ViewState["back_no"]=0;
//隐藏的窗体字段ViewState,是页面级的
}
ViewState["back_no"]=Convert.ToInt32(ViewState["back_no"])+1;
}
2.在前台my.aspx页面加入语句:
<input type="button" value="返回上一页"
onclick=‘history.go(-<%= (int)ViewState["back_no"] %>)‘>
this.RegisterClientScriptBlock(function, "<script>history.go(-2);</script>");
Response.Write("<script>history.go(-2);</script>");
前台代码:
onclick="window.history.back(-1);"
ASP.net(c#)做返回上一页效果(后退)--代码
protected void Page_Load(object sender, EventArgs
e)
{
if
(!IsPostBack)
{
ViewState["BackUrl"] =
Request.UrlReferrer.ToString();
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
Response.Redirect(ViewState["BackUrl"].ToString());
}
sharepoint2013里面这么实现
public static string f;//全局变量 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ViewState["demo"] = 0; if (Request.UrlReferrer != null) { ViewState["retu"] = Request.UrlReferrer.AbsoluteUri;//获取前一个url就是返回(后退) string sur = ViewState["retu"].ToString(); f = sur; } } }
调用
protected void Button1_Click(object sender, EventArgs
e)
{
Response.Redirect(f);
//重定项一个网址
}