Solved

ViewState not working across postbacks

Posted on 2010-09-22
7
712 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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