Invalid viewstate viewstate corrupted ?
Ever got this error and thought what you did to deserve this ? since nowhere have you played with the viewstate of the page…
while all you did was use the statement : Server.Trasnfer(PageURL, true);
well here is the answer
Thats b’coz the viewstate is invalid in the second page and how so ? well lets start with what does Server.Trasfer() with preserveForm attribute set to true does.
The statement is going to transfer to the new page and keep the form members intact so that you can access it from the next page.
Which in turns means every control on the form will be accessible from the second form and since viewstate of a page is stored in a encrypted format in a hidden textbox on the form it will also
be accessible and present in the second form.
Now here lies the problem.
The second form will contain its own viewstate and now since we have used preserve form = true the viewstate of the previous form will also be present in the second form which is a
complete nono since how can one page have 2 viewstates.This is the reason why we get the above error.
Note : If you are running your application on a web farm then the error might also be because the validation key used for validating the viewstate is different for each
server in the web farm.