473,659 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P age
{
protected System.Web.UI.W ebControls.Butt on Button1;
protected int modPageMode;
private void Page_Load(objec t sender, System.EventArg s e)
{
Page.EnableView State = true;

// Initial page load
if (!Page.IsPostBa ck)
{
modPageMode = 1;
}
// Post back
else
{
// Set the page mode
modPageMode = (int)ViewState["PageMode"];
}
}
private void Page_Unload(obj ect sender, System.EventArg s e)
{
ViewState["PageMode"] = modPageMode.ToS tring();
}

private void Button1_Click(o bject sender, System.EventArg s e)
{
modPageMode = 2;
}
}
Nov 18 '05 #1
1 2409
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*******@yaho o.com> wrote in message
news:ce******** *************** ***@posting.goo gle.com...
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.P age
{
protected System.Web.UI.W ebControls.Butt on Button1;
protected int modPageMode;
private void Page_Load(objec t sender, System.EventArg s e)
{
Page.EnableView State = true;

// Initial page load
if (!Page.IsPostBa ck)
{
modPageMode = 1;
}
// Post back
else
{
// Set the page mode
modPageMode = (int)ViewState["PageMode"];
}
}
private void Page_Unload(obj ect sender, System.EventArg s e)
{
ViewState["PageMode"] = modPageMode.ToS tring();
}

private void Button1_Click(o bject sender, System.EventArg s 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
46965
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
20356
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 , for example, when the file doesnt exists, i should not return any reference to a bad constructed object, so i need something as a NULL reference object. I suppose i could return a pointer instead, but i have some code written with references which...
13
3097
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" automatically after programs do "delete p"?
14
3143
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 it makes difference to explicitly put them to null after working with them is done - it somehow makes the GC collect them sooner, like here: void SomeFunc() { MyClass c = new MyClass();
5
8076
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 thing to do. And I wonder why VB .NET keeps silence and makes such function return some default value instead. Isn't it error-prone? -- Dmitriy Lapshin
42
3131
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 array (size is 10*10), setting all the values inside the 10*10 matrix to zero. My C-function looks like this:
4
5129
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 control which one is visible based on buttons pushed. I can do single operations, but I get an error when I click SELECT on the GRIDVIEW, then UPDATE on the DetailsView then SELECT on the Gridview again. I will have to send the code in a follow-on...
6
1713
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"; $body = 'The first line\n'; $body .= 'The second line.'; $headers = 'From: webmaster@example.com';
10
1548
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, is this a good place to employ a user-defined Type? The FN would reside in a global module. When called, it does return one value considered to be the most important. But while it's running, it does calculate several more important values that...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.