Invalid ViewState Error after Multiple PostBacks

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am receiving an Invalid ViewState error after posting back to the same page
twice. Consistently the error occurs after the second postback and not after
the first.

I have looked into creating a static machinekey in the machine.config and
that did not help. I believe that issue only occurred when there was an
inconsistent viewstate error. The error I am faced with consistently occurs.

Are there any known problems with the ViewState when posting back to the
same page multiple times? Any help would be much appreciated.
 
Jamie,

What's the exact error being returned?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Justin,

See below...

Exception Details: System.Web.HttpException: The viewstate is invalid for
this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +139
System.Web.UI.Page.LoadPageViewState() +17
System.Web.UI.Page.ProcessRequestMain() +423
 
Jamie,

See if this helps...

http://www.extremeexperts.com/Net/FAQ/ViewStateisCorrupt.aspx

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jamie said:
Justin,

See below...

Exception Details: System.Web.HttpException: The viewstate is invalid for
this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +139
System.Web.UI.Page.LoadPageViewState() +17
System.Web.UI.Page.ProcessRequestMain() +423




S. Justin Gengo said:
Jamie,

What's the exact error being returned?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Unfortunately I have already tried setting the EnableViewStateMac attribute =
"false" and it did not fix the issue. Also, I am not using Server.Transfer
Jamie,

See if this helps...

http://www.extremeexperts.com/Net/FAQ/ViewStateisCorrupt.aspx

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jamie said:
Justin,

See below...

Exception Details: System.Web.HttpException: The viewstate is invalid for
this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +139
System.Web.UI.Page.LoadPageViewState() +17
System.Web.UI.Page.ProcessRequestMain() +423




S. Justin Gengo said:
Jamie,

What's the exact error being returned?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
I am receiving an Invalid ViewState error after posting back to the same
page
twice. Consistently the error occurs after the second postback and not
after
the first.

I have looked into creating a static machinekey in the machine.config
and
that did not help. I believe that issue only occurred when there was
an
inconsistent viewstate error. The error I am faced with consistently
occurs.

Are there any known problems with the ViewState when posting back to
the
same page multiple times? Any help would be much appreciated.
 
Jamie,

Is it possible for you to post the code or at least the parts of it or an
example that you deem relevant? It's going to be almost impossible to figure
out what's going on without seeing an example.

Thanks,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jamie said:
Unfortunately I have already tried setting the EnableViewStateMac
attribute =
"false" and it did not fix the issue. Also, I am not using
Server.Transfer
Jamie,

See if this helps...

http://www.extremeexperts.com/Net/FAQ/ViewStateisCorrupt.aspx

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jamie said:
Justin,

See below...

Exception Details: System.Web.HttpException: The viewstate is invalid
for
this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the
current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +139
System.Web.UI.Page.LoadPageViewState() +17
System.Web.UI.Page.ProcessRequestMain() +423




:

Jamie,

What's the exact error being returned?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
I am receiving an Invalid ViewState error after posting back to the
same
page
twice. Consistently the error occurs after the second postback and
not
after
the first.

I have looked into creating a static machinekey in the
machine.config
and
that did not help. I believe that issue only occurred when there
was
an
inconsistent viewstate error. The error I am faced with
consistently
occurs.

Are there any known problems with the ViewState when posting back to
the
same page multiple times? Any help would be much appreciated.
 
Jamie said:
Justin,

See below...

Exception Details: System.Web.HttpException: The viewstate is invalid
for this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page
and might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +139
System.Web.UI.Page.LoadPageViewState() +17
System.Web.UI.Page.ProcessRequestMain() +423

If you do a View / Source on the error page, you'll get a more complete
stack trace in the HTML comment at the bottom of the page.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003
 
I stripped the code down a little but here it is... There are two classes: 1
regular aspx page "Class1.aspx" and another web control "WebControl.cs" that
is implemented by Class1. Class1 passes several values to WebControl.cs via
the ViewState which also gets changed during the rendering process.

public class Class1 : System.Web.UI.Page
{
protected Controls.WebControl WebCtl;
protected System.Web.UI.WebControls.Repeater ceParamRep;
protected System.Web.UI.HtmlControls.HtmlForm frmDefault;
protected System.Web.UI.WebControls.Label headerlabel;

private void Page_Load(object sender, System.EventArgs e)
{
string passedItem;
WebControl.PassedItem = passedItem;
}
}

public class WebControl : System.Web.UI.WebControls.WebControl,
System.Web.UI.IPostBackDataHandler
{
[Bindable(true),
Category("Item"),
DefaultValue("")]
public string PassedItem
{
get
{
object obj = ViewState["passedItem"];
return (obj == null) ? String.Empty : (string)obj;
}
set
{
ViewState["passedItem"] = value;
}
}

protected override void Render(HtmlTextWriter output)
{
if (Page != null)
{
output.Write(this.PassedItem);
}
}

bool IPostBackDataHandler.LoadPostData(string postDataKey,
NameValueCollection postCollection)
{
bool change = false;
string ssvalue = postCollection[this.SSHelper];
if (ssvalue != null)
{
if(String.Compare(ssvalue,this.PassedItem.ToString(),true) != 0)
{
this.PassedItem = ssvalue;
// If there is a change, raise a change event.
change = true;
}
}
string modevalue = postCollection[this.ModeHelper];
if (modevalue !=null)
{
if(String.Compare(modevalue,this.Mode.ToString(),true) != 0)
{
this.Mode = modevalue;
change = true;
}
}
return change;
}

void IPostBackDataHandler.RaisePostDataChangedEvent()
{
// There was a change, so raise any events.
if (ConfigurationChanged != null)
{
ConfigurationChanged(this, EventArgs.Empty);
}
}



S. Justin Gengo said:
Jamie,

Is it possible for you to post the code or at least the parts of it or an
example that you deem relevant? It's going to be almost impossible to figure
out what's going on without seeing an example.

Thanks,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jamie said:
Unfortunately I have already tried setting the EnableViewStateMac
attribute =
"false" and it did not fix the issue. Also, I am not using
Server.Transfer
Jamie,

See if this helps...

http://www.extremeexperts.com/Net/FAQ/ViewStateisCorrupt.aspx

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Justin,

See below...

Exception Details: System.Web.HttpException: The viewstate is invalid
for
this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the
current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +139
System.Web.UI.Page.LoadPageViewState() +17
System.Web.UI.Page.ProcessRequestMain() +423




:

Jamie,

What's the exact error being returned?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
I am receiving an Invalid ViewState error after posting back to the
same
page
twice. Consistently the error occurs after the second postback and
not
after
the first.

I have looked into creating a static machinekey in the
machine.config
and
that did not help. I believe that issue only occurred when there
was
an
inconsistent viewstate error. The error I am faced with
consistently
occurs.

Are there any known problems with the ViewState when posting back to
the
same page multiple times? Any help would be much appreciated.
 
focus on this article
http://support.microsoft.com/default.aspx?scid=kb;en-us;555353

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Jamie said:
I stripped the code down a little but here it is... There are two classes: 1
regular aspx page "Class1.aspx" and another web control "WebControl.cs" that
is implemented by Class1. Class1 passes several values to WebControl.cs via
the ViewState which also gets changed during the rendering process.

public class Class1 : System.Web.UI.Page
{
protected Controls.WebControl WebCtl;
protected System.Web.UI.WebControls.Repeater ceParamRep;
protected System.Web.UI.HtmlControls.HtmlForm frmDefault;
protected System.Web.UI.WebControls.Label headerlabel;

private void Page_Load(object sender, System.EventArgs e)
{
string passedItem;
WebControl.PassedItem = passedItem;
}
}

public class WebControl : System.Web.UI.WebControls.WebControl,
System.Web.UI.IPostBackDataHandler
{
[Bindable(true),
Category("Item"),
DefaultValue("")]
public string PassedItem
{
get
{
object obj = ViewState["passedItem"];
return (obj == null) ? String.Empty : (string)obj;
}
set
{
ViewState["passedItem"] = value;
}
}

protected override void Render(HtmlTextWriter output)
{
if (Page != null)
{
output.Write(this.PassedItem);
}
}

bool IPostBackDataHandler.LoadPostData(string postDataKey,
NameValueCollection postCollection)
{
bool change = false;
string ssvalue = postCollection[this.SSHelper];
if (ssvalue != null)
{
if(String.Compare(ssvalue,this.PassedItem.ToString(),true) != 0)
{
this.PassedItem = ssvalue;
// If there is a change, raise a change event.
change = true;
}
}
string modevalue = postCollection[this.ModeHelper];
if (modevalue !=null)
{
if(String.Compare(modevalue,this.Mode.ToString(),true) != 0)
{
this.Mode = modevalue;
change = true;
}
}
return change;
}

void IPostBackDataHandler.RaisePostDataChangedEvent()
{
// There was a change, so raise any events.
if (ConfigurationChanged != null)
{
ConfigurationChanged(this, EventArgs.Empty);
}
}



S. Justin Gengo said:
Jamie,

Is it possible for you to post the code or at least the parts of it or an
example that you deem relevant? It's going to be almost impossible to figure
out what's going on without seeing an example.

Thanks,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Jamie said:
Unfortunately I have already tried setting the EnableViewStateMac
attribute =
"false" and it did not fix the issue. Also, I am not using
Server.Transfer
on the page.

:

Jamie,

See if this helps...

http://www.extremeexperts.com/Net/FAQ/ViewStateisCorrupt.aspx

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Justin,

See below...

Exception Details: System.Web.HttpException: The viewstate is invalid
for
this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the
current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +139
System.Web.UI.Page.LoadPageViewState() +17
System.Web.UI.Page.ProcessRequestMain() +423




:

Jamie,

What's the exact error being returned?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
I am receiving an Invalid ViewState error after posting back to the
same
page
twice. Consistently the error occurs after the second postback and
not
after
the first.

I have looked into creating a static machinekey in the
machine.config
and
that did not help. I believe that issue only occurred when there
was
an
inconsistent viewstate error. The error I am faced with
consistently
occurs.

Are there any known problems with the ViewState when posting back to
the
same page multiple times? Any help would be much appreciated.
 
Alvin,

I had seen this article and tried some of the suggestions such as using a
static machinekey, but that did not work. Also, the error is not
intermittent as it always occurs after the second postback of the page. I am
running this on a local IIS server which does have virus protection although
I don't think this would be an issue since the postback works fine the first
time.

Is there anything related to viewstate and multiple postbacks where I have
to issue some type of clear statement to the page? The only solution I can
think of is to eliminate the use of ViewState altogether.

Alvin Bruney - ASP.NET MVP said:
focus on this article
http://support.microsoft.com/default.aspx?scid=kb;en-us;555353

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Jamie said:
I stripped the code down a little but here it is... There are two classes: 1
regular aspx page "Class1.aspx" and another web control "WebControl.cs" that
is implemented by Class1. Class1 passes several values to WebControl.cs via
the ViewState which also gets changed during the rendering process.

public class Class1 : System.Web.UI.Page
{
protected Controls.WebControl WebCtl;
protected System.Web.UI.WebControls.Repeater ceParamRep;
protected System.Web.UI.HtmlControls.HtmlForm frmDefault;
protected System.Web.UI.WebControls.Label headerlabel;

private void Page_Load(object sender, System.EventArgs e)
{
string passedItem;
WebControl.PassedItem = passedItem;
}
}

public class WebControl : System.Web.UI.WebControls.WebControl,
System.Web.UI.IPostBackDataHandler
{
[Bindable(true),
Category("Item"),
DefaultValue("")]
public string PassedItem
{
get
{
object obj = ViewState["passedItem"];
return (obj == null) ? String.Empty : (string)obj;
}
set
{
ViewState["passedItem"] = value;
}
}

protected override void Render(HtmlTextWriter output)
{
if (Page != null)
{
output.Write(this.PassedItem);
}
}

bool IPostBackDataHandler.LoadPostData(string postDataKey,
NameValueCollection postCollection)
{
bool change = false;
string ssvalue = postCollection[this.SSHelper];
if (ssvalue != null)
{
if(String.Compare(ssvalue,this.PassedItem.ToString(),true) != 0)
{
this.PassedItem = ssvalue;
// If there is a change, raise a change event.
change = true;
}
}
string modevalue = postCollection[this.ModeHelper];
if (modevalue !=null)
{
if(String.Compare(modevalue,this.Mode.ToString(),true) != 0)
{
this.Mode = modevalue;
change = true;
}
}
return change;
}

void IPostBackDataHandler.RaisePostDataChangedEvent()
{
// There was a change, so raise any events.
if (ConfigurationChanged != null)
{
ConfigurationChanged(this, EventArgs.Empty);
}
}



S. Justin Gengo said:
Jamie,

Is it possible for you to post the code or at least the parts of it or an
example that you deem relevant? It's going to be almost impossible to figure
out what's going on without seeing an example.

Thanks,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Unfortunately I have already tried setting the EnableViewStateMac
attribute =
"false" and it did not fix the issue. Also, I am not using
Server.Transfer
on the page.

:

Jamie,

See if this helps...

http://www.extremeexperts.com/Net/FAQ/ViewStateisCorrupt.aspx

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Justin,

See below...

Exception Details: System.Web.HttpException: The viewstate is invalid
for
this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the
current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The viewstate is invalid for this page and
might be corrupted.]
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +139
System.Web.UI.Page.LoadPageViewState() +17
System.Web.UI.Page.ProcessRequestMain() +423




:

Jamie,

What's the exact error being returned?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
I am receiving an Invalid ViewState error after posting back to the
same
page
twice. Consistently the error occurs after the second postback and
not
after
the first.

I have looked into creating a static machinekey in the
machine.config
and
that did not help. I believe that issue only occurred when there
was
an
inconsistent viewstate error. The error I am faced with
consistently
occurs.

Are there any known problems with the ViewState when posting back to
the
same page multiple times? Any help would be much appreciated.
 

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

Back
Top