Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Validation of viewstate MAC failed" on postback to a different page

I'm working on a web form which works fine as long as it posts back to itself. In Reports.aspx I have:

<form runat="server" method="post">

but, when I try to get it to post to a different page:

<form runat="server" method="post" action="DisplayReport.aspx">

I get the "Validation of viewstate MAX failed" error. I've tried setting the machine key and disabling the viewstate in web.config, but nothing seems to help. Am I stuck posting back to the same page? If so what is the point of the action attribute?

like image 680
Ferruccio Avatar asked Dec 22 '22 09:12

Ferruccio


1 Answers

You can submit to a different page, but you need to use the PostBackUrl property of a button, not the form's action attribute.

Instead of this:

<form runat="server" method="post" action="DisplayReport.aspx">
    <!-- form stuff goes here -->
    <asp:button runat="server" text="Submit" />
</form>

Do this:

<form runat="server">
    <!-- form stuff goes here -->
    <asp:button runat="server" text="Submit" postbackurl="DisplayReport.aspx" />
</form>
like image 138
LukeH Avatar answered Apr 30 '23 05:04

LukeH