1
votes

Hi i have the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>
  <title></title></head><body><form method="POST" action="search.aspx" runat="server">     Name <input type="text" name="Name"/>Age <input type="text" name="Age"/><input type="submit" /></form></body></html>

It's simple asp.net form with two fields name and age and a submit button. but When i click the submit button, i recieve the following 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. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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.

This error disappears if i remove runat=server from the form. Unfortunately i have a dropdown list which to populated from db with runat=server in the form tag. Any idea why i can't post using runat=server? the code that i will be using for drop down list is as follows:

<label>Location</label> <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:web3ConnectionString1 %>" 
    SelectCommand="SELECT DISTINCT location FROM properties"></asp:SqlDataSource>


            <asp:DropDownList id="location" runat="server" DataSourceID="SqlDataSource2" DataTextField="location" DataValueField="location" >


            </asp:DropDownList>

but before that the simple form needs to start posting values.

Regards, Sohail.

2
I don't know if this is causing the problem, but off the bat I can see that your form tag needs an ID attribute.Joel Etherton

2 Answers

1
votes

If this application isn't running on a web farm, try setting the enableViewStateMac key to false in the web.config:

<pages enableViewStateMac="false">
2
votes

Your form tag is malformed. It should look more like:

<form id="MyForm" runat="server">

It shouldn't specify method or action. These specifications may be ruining your viewstate or changing the MAC in some way.