SPUtility.ValidateFormDigest breaks ASP.Net server side validation

I have a Web Part which is using SPSecurity.RunWithElevatedPrivileges, and thus needs to call SPUtility.ValidateFormDigest. However, this apparently causes it to ignore all ASP.Net validators server side. The validation functions are being called, but the IsValid result seems to be either overwritten or ignored. What is causing this, and how do I fix it?

Broadly speaking, I have a Visual Web Part that is a form. It has a bunch of input controls, with various required, regular expression, and custom validators. And basically:

protected void SubmitButton_Click(object sender, EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(
delegate { do a bunch of stuff including creating list items });
}

but a lot more complicated because there are a bunch of views and different submit buttons.

Originally I had SPUtility.ValidateFormDigest(); in Page_Load. I have also tried placing it directly before the SPSecurity.RunWithElevatedPrivileges in the click event handler, but that has not resolved the issue.

=================

  

 

What do you mean with thus needs to call SPUtility.ValidateFormDigest? Can you post your code?
– Robert Lindgren♦
Jan 5 ’15 at 18:26

1

 

@RobertLindgren If the method that is passed to the RunWithElevatedPrivileges method includes a write operation, either of the SPUtility.ValidateFormDigest() or SPWeb.ValidateFormDigest() methods should be called before a call is made to RunWithElevatedPrivileges.
– HamHamJ
Jan 5 ’15 at 18:34

  

 

Ah you’re making a write operation in the elevation, it was not fully clear from your question
– Robert Lindgren♦
Jan 5 ’15 at 18:44

=================

=================