0

I already searched on many Websites but I found no solution :-( I want to use the ViewState after the Postback (after clicking on a Image link).

my PageLoad:

 protected void Page_Load(object sender, EventArgs e)
    {
        ...

        if (!IsPostBack && !IsCallback)
        {
            pivotPlan.DataSource = Keys.ToList();
            ViewState["pivotPlan"] = pivotPlan.DataSource;
        }
        else
        {
            pivotPlan.DataSource = ViewState["pivotPlan"];
        }
    }

The strange Thing is that the ViewState is null when I step through the code and the Debugger reaches the masterpage. I enabled the ViewState in the masterpage, but when I click on the imagebutton I will get this error:

Server Error in '/' Application.

The state information is invalid for this page and might be corrupted. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The state information is invalid for this page and might be corrupted.

Source Error: [No relevant source lines]

Source File: c:\Users\neunin\AppData\Local\Temp\Temporary ASP.NET Files\root\7b4d9801\69af7fa1\App_Web_2nxwrvxv.1.cs Line: 0

I really don't have a clue what the Problem is :( Maybe anybody can help me? Thank you very much in advance! :-)

Regards, Nina

  • do you have viewstate enabled on your page (not the master page)? – Karthik Ganesan Jun 04 '14 at 14:14
  • yes: <%@ Page Title="" Language="C#" EnableViewState="true" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeBehind="PlanUebersicht.aspx.cs" Inherits="Auditor.PlanUebersicht" %> – user3604684 Jun 04 '14 at 14:22

1 Answers1

0

That source file looks suspicious to me. If you created a new ASP.NET website, tried adding some basic info to ViewState, and then retrieving it, does it work? I'm wondering if you should delete all ASP.NET temp files and try compiling\running the app again, check out this answer: ASP.NET Temporary files cleanup

Hope this helps, and welcome to SO :)

Community
  • 1
  • 1
ewitkows
  • 3,528
  • 3
  • 40
  • 62
  • Thank you for your reply and hello to SO :-) I tried it on the Default.aspx with a simple string in the viewstate. this works!! I tried it then with the simple string on my page.. this works too. But when I try the same Thing with a list ob objects, it does not work :( I also marked the classes as [Serializeable) .. but maybe the ViewState does not "like" List of Objects with objects in it... ? (The datasource Comes from EntitiyFramework) – user3604684 Jun 04 '14 at 14:48
  • you mean the class "Keys" is marked as serializable?? – Karthik Ganesan Jun 04 '14 at 15:05
  • Hmm.. I'm pretty sure I have stored object lists in viewstate before. Have you tried performing a cast when adding\retrieving the values from viewstate? – ewitkows Jun 04 '14 at 18:09