Solved

ViewState not working across postbacks

Posted on 2010-09-22
7
714 Views
Last Modified: 2012-05-10
I am trying to set a value into ViewState but the value isn't saving across postbacks. (I am actually trying to save a seriazable class, but for simplicity I am testing using a simple string value which isn't saving either).

I have tried manually setting the EnabledViewState = true property in the page directive of the master page, and I am also testing to see whether ViewState is enabled at the start of the method, which it is - but still the value is being reset on every postback.

The OnPreRender occurs late enough in the Page Lifecycle so that isn't the issue.  

Any ideas?

protected override void OnPreRender(EventArgs e)
    {
        bool viewState = this.IsViewStateEnabled;

        if (!Page.IsPostBack)
        {
            if (ViewState["Test"] == null)
                ViewState["Test"] = "This is a test";

            string test = (string)ViewState["Test"];
        }
    }

Open in new window

0
Comment
Question by:markerasmus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 5

Assisted Solution

by:Siyamala
Siyamala earned 250 total points
ID: 33733278
try
change asp page - first line

AutoEventWireup="true" to false
0
 

Author Comment

by:markerasmus
ID: 33735129
Nope, that didn't work.
0
 
LVL 10

Accepted Solution

by:
codingbeaver earned 250 total points
ID: 33736016
My guess is it has something to do with when you set ViesState value. The order of firing events is important.
0
 

Author Comment

by:markerasmus
ID: 33736459
I've decided to use session state instead.
0
 
LVL 5

Expert Comment

by:Siyamala
ID: 33989220
Hi,

My answer answer has been accepted as a Assisted Solution ,But still the score Points is not Updated.

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question