Click here to Skip to main content
12,629,978 members (26,571 online)
Click here to Skip to main content


37 bookmarked

Access ViewState Across Pages

, 30 Jun 2009 CPOL
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

Talking Dotnet
Technical Lead
India India
I am an experienced Software Developer with 8+ years of hands-on experience working with Microsoft .NET technology (ASP.NET, C#, VB.NET,SQL Server).

Visit Talking Dotnet
Read Difference between Angular 1.x and Angular 2
For ASP.NET Core, read ASP.NET Core Articles
For Entity Framework Core, read Entity Framework Core Articles

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161205.3 | Last Updated 30 Jun 2009
Article Copyright 2009 by Talking Dotnet
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid