R – Viewstate error on SharePoint custom site page with SPGridView

sharepointspgridview

I've got a custom site page in Windows SharePoint Services 3.0 that contains an SPGridView. When I use the search box on this page, I get the following error:

Unable to validate data.   at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) 
   at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)  

Removing the SPGridView from the page fixes this problem, but otherwise I'm not sure how to go about troubleshooting the problem.

This is on a fresh, default install of WSS3, so I don't think it has to do with any other customizations (master pages, etc.). I have one other custom site page in this feature (which doesn't include an SPGridView), but I can use the search box on that page without causing an error.

Best Solution

OK, I finally figured out what the problem was (in my particular case, anyway): I was specifying the DataKeyNames attribute of the SPGridView. After removing that attribute, search worked just fine.

Related Question