In ASP.net 2.0, the PreviousPage property of a web page does not have a ViewState collection. I want to use this collection to transfer information between pages.
views:
1230answers:
3
A:
Use HttpContext.Current.Items instead...ViewState is only good for the page it is on.
FlySwat
2008-10-03 20:47:46
This method is simple and clean. I like it.
Keith Walton
2008-10-03 21:09:55
I tried to use this method, but I am posting directly from a link on the first page. No code is executing where I can populate the HttpContext.Current.Items colection: <asp:linkbutton runat="server" id="Upload" text="Upload" postbackurl="~/uploadfeescheduleterms.aspx" />
Keith Walton
2008-10-03 22:24:28
+1
A:
View State is exclusive to the page.
If you want to transfer items,
- you can persist the data in a database, file, forms auth ticket or other cookie (Dont use Session or HttpContext.Current.Cache if you can help it)
- do a cross page post - from your first page, post back to the second page (and get the details from HttpContext.Current.Request.Form[] collection)
- put the values in a query string
StingyJack
2008-10-03 20:54:54
I ended up using a cross page post, but accessing a public property on the first page (see below).
Keith Walton
2008-10-03 22:29:11
A:
You can't directly. (See http://msdn2.microsoft.com/en-us/library/ms178139(vs.80).aspx
Here's what you can do -
Create public properties on the first page exposing the information you want to share. On the second page, set the PreviousPageType to the first page in the header of aspx file:
<%@ previouspagetype virtualpath="~/firstpage.aspx" %>
Then, get the values of these properties in the Load event of the second page:
If (Not MyBase.IsPostBack) Then
_someValue = Me.PreviousPage.SomeValue
End If
Keith Walton
2008-10-03 21:01:10
Use the @ PreviousPageType directive to get strong typing against the PreviousPage property. "_someValue = firstPage.SomeValue" becomes "_someValue = Me.PreviousPage.SomeValue"
Keith Walton
2008-10-08 16:58:25