Reputation: 1265
Im working with asp.net framework 4.0 and I have this code:
form id="form1" runat="server" method="get" action="Profile.aspx"
// some code
asp:Button runat="server" ID="SubmitButton" Text="Submit"
Each time i click the submit button i get this error:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
any idea how to fix it ???
Upvotes: 2
Views: 1834
Reputation: 905
If you want to send post back to your current page, remove in form tag method="get" action="Profile.aspx" attributes. And handle in codebehind post data from your page.
If your want to send data you another page like Profile.aspx, use PostBackUrl attribute of the button control, like Stilgar wrote for you. And then in Profile.aspx codebehind to get access to control from your current page use somethink like this:
If(Page.PreviousPage != null)
{
var textBox = Page.PreviousPage.FindControl("ControlID") as TextBox;
if(textBox != null)
{
//Use your logic here
}
}
Hope it will be helpful for you!
Best regards, Dima.
Upvotes: 1
Reputation: 23551
This is caused by cross-page POST (i.e. you are submitting the ViewState of the first page to the second). You can add PostBackUrl to the button like this:
<asp:Button runat="server" ID="SubmitButton" Text="Submit" PostBackUrl="~/WebForm2.aspx" />
Alternatively you can handle the click event of the button in the first page, move some of the logic in this handler and do a Response.Redirect (i.e. GET request) to the second page. The right solution depends on your particular case.
Upvotes: 2