Visual Studio .NET 2003WebFormsVisual Studio 2005.NET 2.0C# 2.0IntermediateDevVisual StudioWindows.NETASP.NETC#
如何从下一页访问此页面的 viewstate 值?






1.25/5 (6投票s)
2007年9月20日

22689
ViewState 是页面特定的;它包含有关嵌入在页面上的控件的信息。
引言
如何从下一页访问此页面的 viewstate 值?
背景
ViewState 是页面特定的;它包含有关嵌入在
特定页面上的控件的信息。 ASP.NET 2.0 通过嵌入一个隐藏的输入字段名称来解决这个问题,
__POSTBACK。 只有当页面上存在 IButtonControl 且其 PostBackUrl 属性设置为非空值时,才会嵌入此字段。
页面及其 PostBackUrl 属性设置为非空值时,才会嵌入此字段。该字段包含发布页面的 ViewState
状态信息。
使用代码
如何使用代码的简要说明。 类名、方法和属性,任何技巧或提示。
要访问发布页面的 ViewState,可以使用页面的新 PreviousPage 属性
//Page poster = this.PreviousPage; Then you can find any control from the previous page and read its state: //Label posterLabel = poster.findControl("myLabel"); //string lbl = posterLabel.Text; This cross-page post back feature also solves the problem of posting a Form to multiple pages, because each control, in theory, can point to different post back URL.
关注点
您可以回发到任何页面,也可以回发到另一个应用程序中的页面。 但是,如果您将页面发布到另一个应用程序,则 PreviousPage 属性将返回 null。 这是一个
重要的限制,因为它意味着如果您想使用 ViewState,则会被限制,
例如,只能发布到同一虚拟目录中的页面。 尽管如此,这仍然是一个非常
对 ASP.NET 功能的可接受的补充。