How do you access the ViewState collection from PreviousPage in a cross callback?

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.

+3
source share
4 answers

View state is exclusive to the page.

If you want to transfer items,

  • you can save data in a database, file, auth tickets or other cookies (do not use Session or HttpContext.Current.Cache if you can help)
  • do a cross page - from your first page, return to the second page (and get information from the HttpContext.Current.Request.Form [] collection)
  • enter values ​​in the query string
+1

HttpContext.Current.Items ... ViewState , .

+1

PreviousPageType, - , . ,

public class BaseCrossPage:System.Web.UI.Page
{
     public List<Guid> Invitees = new List<Guid>();

}

,

public partial class Default : BaseCrossPage
{

    protected void Page_Load(object sender, EventArgs e)
    {

       this.Invitees = LoadInvitees();
    }


}

, , , , BaseCrossPage...

public partial class secondPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        BaseCrossPage p = (BaseCrossPage)PreviousPage;
        List<Guid> Invitees = p.InvitedTeams
    }
}

"viewstate" ...

+1

. (. http://msdn2.microsoft.com/en-us/library/ms178139(vs.80).aspx

-

Create public properties on the first page by exposing the information you want to provide. On the second page, set the PreviousPageType parameter to the first page in the aspx file header:

<%@ 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
0
source

Source: https://habr.com/ru/post/1697881/


All Articles