"View State Invalid" Error While Submitting Form thru JavaScript

  • Thread starter Thread starter Vinod I
  • Start date Start date
V

Vinod I

Hi Team,

When I tryed following code, I am getting the Runtime Error as
"The View State is invalid for this page and might be corrupted."
Exception Details: System.Web.HttpException: The View State is invalid for
this page and might be corrupted.
Stack Trace:
[HttpException (0x80004005): The View State is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +150
System.Web.UI.Page.LoadPageViewState() +16
System.Web.UI.Page.ProcessRequestMain() +421



And My Code is in ".js" file:
function save()

{

document.forms(0).method = "post";

document.forms(0).action = "formsave1.aspx";

document.forms(0).submit();

}

Please let me know wat can be the reason.

Thanks in advance..

cheers !!
 
If you change the action attribute of the form then the Viewstate will
become invalid, you will be posting back data to a different place. The
idea with a webform is that it is always posted back to itself, viewstate is
loaded so your page knows when to run onchange, onclick.. etc server side
events. If you postback to a different page then there would be no way of
knowing if the controls would be the same (and if they were what would be
the point of having a separate webform anyway).

Hope that helps you solves your problem, the only time I can think of that
you would want to overwrite the action attribute using Javascript is if you
have made a previous call to Context.Rewritepath in an HttpModule. You
could then use Javascript to correct the incorrect action attribute that is
output by ASP.net, which causes exactly the same error you are seeing.

Matt
http://www.3internet.com
Inigo Content Management - c# asp.net cms
 
Back
Top