Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Access ViewState Across Pages

, 30 Jun 2009
This article demonstrates how we can share ViewState across pages
using System;
using System.Reflection;
using System.Web.UI;

public partial class AccessViewState : System.Web.UI.Page
    private StateBag PreviousPageViewState
            StateBag returnValue = null;
            if (PreviousPage != null)
                Object objPreviousPage = (Object)PreviousPage;
                MethodInfo objMethod = objPreviousPage.GetType().GetMethod("ReturnViewState");
                return (StateBag)objMethod.Invoke(objPreviousPage, null);

                //foreach (MethodInfo objMethodInfo in obj.GetType().GetMethods())
                //    if (objMethodInfo.Name == "ReturnViewState")
                //    {
                //        return (StateBag)objMethodInfo.Invoke(obj, null);
                //    }
            return returnValue;

    protected void Page_Load(object sender, EventArgs e)
        if (PreviousPage != null)
            if (PreviousPageViewState != null)
                Label1.Text = PreviousPageViewState["Page1"].ToString();

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

jQuery By Example
Technical Lead
India India
I am an experienced Software Developer with 6+ years of hands-on experience working with Microsoft .NET technology (ASP.NET, C#, VB.NET,SQL Server).
Visit my blog and you can also follow me on Facebook
Follow on   Twitter   Google+

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 30 Jun 2009
Article Copyright 2009 by jQuery By Example
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid