Solved

ViewState not working across postbacks

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

17 Experts available now in Live!

Get 1:1 Help Now