keyongtech


  keyongtech > dotnet.framework.aspnet.* > dotnet.framework.aspnet.main > 04/2004

 #1  
04-27-04, 12:42 AM
Steph
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;
}
}
 #2  
04-27-04, 01:08 AM
bruce barker
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" <bajaguide> wrote in message
news:4b56
[..]
Similar Threads
"Failed to load viewstate" when clicking button

Hi, I have a problem with an ImageButton inside a web user control. It works in some pages, but in others, it just keeps with the "Failed to load viewstate" error....

Reccomended ways of saving WinForms' "viewstate"?

Hi everyone, I was curious....is there a preferred way to save/serialize the settings of WinForm's controls? I'd like to be able to save the user's values when they close...

"Stream was not readable" error when deserializing object from viewstate

Being a newbie regarding serialization and memorystreams, I was trying to see if i could improve page performance (avoiding going to the db on a postback) by saving my...

How to "track" a (child) control's ViewState / SaveViewState?

Can you post the code? It is hard to say anything exact before that? Do you bind the DDL *after* it is added to the Controls collection of your parent control?

Viewstate Corrupt error message after "Worker Process" recycling

Hi There, I have a small ASP.NET application under development. I am using VS.NET 2002 (2003 upgrade is on the way) with .NET Framework 1.1. It is hosted on a web hosting...


All times are GMT. The time now is 01:34 AM. | Privacy Policy