您的位置:首页 > 编程语言 > Go语言

利用history.go页面返回

2010-12-09 20:24 363 查看
开发中经常遇到页面返回的问题,可以有很多种处理方法,我在这里讲一种通用的,简便方法,可以在刷新页面后返回依然有效

//基类

/// <summary>

/// 记录提交页面次数,用在javascript:history.go(<%=GoNum%>)

/// </summary>

public int GoNum

{

get

{

if (this.ViewState["GoNum"] == null)

{

this.ViewState["GoNum"] = "-1";

return -1;

}

else

{

return Convert.ToInt32(this.ViewState["GoNum"]);

}

}

set

{

this.ViewState["GoNum"] = value.ToString();

}

}

/// <summary>

/// 更新数据后返回页数加1

/// </summary>

public void IncreaseGoNum()

{

GoNum += -1;

}

//父页面Page_Load事件

protected void Page_Load(object sender, EventArgs e)

{

if (Page.IsPostBack)

{

IncreaseGoNum();

}

}

//父页面跳转

Redirect(string.Format("Sample.aspx?ID={0}&GoNum={1}", ID, GoNum + 1));

//子页面Page_Load事件

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

GoNum = GetIntFromPage("GoNum");

}

else

{

IncreaseGoNum();

}

}

//使用

<a href="#" class="return" onclick="history.go(<%=GoNum%>)">返回</a>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐