ASP + Ajax + __VIEWSTATE = BAD ?



I have a ASP 2.0 page where I use some Ajax code. The Ajax code
(JavaScript) is inserted from CodeBehind.
In my page I have a submit button and some links for Ajax functions.
When I load the page and use the submit button it give me some results
that is fine.
Then I press the links that activate the Ajax Code the results is
displayed fine on my page.
- BUT -
If I then press the submit button again I get this error:
"The state information is invalid for this page and might be corrupted"
That happens only if I activate the Ajax Code. If I don't I can press
the submit button without any problems.

I think the whole problem is the hidden __VIEWSTATE.
I don't think I use it at all - Is it possible to remove it and still
have sessions variables?

Screen output:
Source Error:
[No relevant source lines]

Source File: d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary
ASP.NET Files\mes\80fad5dd\dd8b6fcb\App_Web_aehuzojs.4.cs Line: 0

Stack Trace:
[FormatException: Invalid character in a Base-64 string.]
System.Convert.FromBase64String(String s) +0
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)

serializedState) +4
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter,
String serializedState) +37
System.Web.UI.HiddenFieldPageStatePersister.Load() +140

[ViewStateException: Invalid viewstate.
Client IP:
Port: 4406
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv: Gecko/20060111 Firefox/

[HttpException (0x80004005): The state information is invalid for this
page and might be corrupted.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String
persistedState, String errorPageMessage, Boolean macValidationError)
System.Web.UI.HiddenFieldPageStatePersister.Load() +240
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +83
System.Web.UI.Page.LoadAllState() +35
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.pluginpage_aspx.ProcessRequest(HttpContext context) in
d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET

System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +64

Sonu Kapoor

To disable the ViewState use the EnableViewState property and set it to false. Although I believe that you should check why you are getting this error. If you are using a third party ajax library, then you might want to ask the author about that as well.

Sonu Kapoor [MVP]


My bad !!!
My Ajax code was returning a complete html page including a new
__VIEWSTATE field.
After a Page.Response.Clear() in the Ajax result code it works just
fine !!!

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question