Solved

ViewState not working across postbacks

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now