473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Problems with ViewState: "function 'ViewState.get_Item' evaluated and returned null"

I am trying to save a simple integer value in ViewState. I set the
value in the Page_Load() event and retrieve it in the function
Page_Unload() event. The value seems to be set correctly, but upon
the next Page_Load(), I get the following error when I try to retrieve
the value from ViewState:

"function 'ViewState.get_Item' evaluated and returned null".

The page does have a form on it with the runat="server" attribute set.
From the MSDN documentation, this seems to be all you have to do.

What am I doing wrong?

I have created a simple test page that illustrates the problem. Here
is the code behind the page:

public class Testing : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected int modPageMode;
private void Page_Load(object sender, System.EventArgs e)
{
Page.EnableViewState = true;

// Initial page load
if (!Page.IsPostBack)
{
modPageMode = 1;
}
// Post back
else
{
// Set the page mode
modPageMode = (int)ViewState["PageMode"];
}
}
private void Page_Unload(object sender, System.EventArgs e)
{
ViewState["PageMode"] = modPageMode.ToString();
}

private void Button1_Click(object sender, System.EventArgs e)
{
modPageMode = 2;
}
}
Nov 18 '05 #1
1 2400
updating viewstate in Unload is not very useful. the page has been rendered,
so the client will not see the update, nor send it back.

PreRender is your last chance to update Viewstate.

-- bruce (sqlwork.com)

"Steph" <ba*******@yahoo.com> wrote in message
news:ce**************************@posting.google.c om...
I am trying to save a simple integer value in ViewState. I set the
value in the Page_Load() event and retrieve it in the function
Page_Unload() event. The value seems to be set correctly, but upon
the next Page_Load(), I get the following error when I try to retrieve
the value from ViewState:

"function 'ViewState.get_Item' evaluated and returned null".

The page does have a form on it with the runat="server" attribute set.
From the MSDN documentation, this seems to be all you have to do.

What am I doing wrong?

I have created a simple test page that illustrates the problem. Here
is the code behind the page:

public class Testing : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected int modPageMode;
private void Page_Load(object sender, System.EventArgs e)
{
Page.EnableViewState = true;

// Initial page load
if (!Page.IsPostBack)
{
modPageMode = 1;
}
// Post back
else
{
// Set the page mode
modPageMode = (int)ViewState["PageMode"];
}
}
private void Page_Unload(object sender, System.EventArgs e)
{
ViewState["PageMode"] = modPageMode.ToString();
}

private void Button1_Click(object sender, System.EventArgs e)
{
modPageMode = 2;
}
}

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: € Alias | last post by:
I have a function named getID3info (lvwDiscInfo.SelectedItem). What is the difference between getID3info (lvwDiscInfo.SelectedItem) and Call getID3info(lvwDiscInfo.SelectedItem) ?
7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
13
by: gary | last post by:
Hi, We all know the below codes are dangerous: { int *p = new int; delete p; delete p; } And we also know the compilers do not delete p if p==NULL. So why compilers do not "p = NULL"...
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
5
by: Dmitriy Lapshin [C# / .NET MVP] | last post by:
Hi all, I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right...
42
by: Martin Jørgensen | last post by:
Hi, I'm trying to move a matlab program into c language. For those who knows matlab, this is the line I want to program in c: hx(1:nx,1:ny) = 0; % nx=10, ny=10 It works on a 2-dimensional...
4
by: scottcly | last post by:
I have a simple editor with a Gridview and a DetailsView. The Gridview handles DELETE and the DetailsView handles UPDATE and ADD. A panel around each one and some minor event handling is used to...
6
by: Kurda Yon | last post by:
Hi everybody, I have a problem with the function "mail". It returns "true" but supposed recipients receive nothing. My code is as follows: $to = $form; $subject = "E-mail Verification";...
10
by: MLH | last post by:
I would like to call a function that "returned" several values - all of which are relevant to the needs of a procedure on a form. I do understand that FN's return a single value. I'm wondering,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.