5

I'm creating a client insert form, in this form has a <asp:HiddenField/> named Id for save selected client id, but when I try submit form, it is on Page enableEventValidation="true" error, when I rename this HiddenField for any other Id, it's work

<asp:HiddenField runat="server" ID="Id" />

My form can submit success when I set enableEventValidation="false", but maybe I will need it in future

How to can I resolve this problem? keep HiddenField named Id

PrintScreen: error message screen

roryok
  • 9,325
  • 17
  • 71
  • 138
Lai32290
  • 8,062
  • 19
  • 65
  • 99

4 Answers4

4

You've pretty much answered your own question. The only way to make this work is set enableEventValidation="false" or rename your HiddenField

Renaming it would be the best solution here, for security reasons

roryok
  • 9,325
  • 17
  • 71
  • 138
  • Okey, but why I can't name "Id" for control? it is reserved word for asp.net? – Lai32290 Feb 18 '14 at 21:28
  • I've actually created a sample app which has a Hidden field named Id and it doesn't cause any issues. There must be something else causing the issue when combined with this field. – roryok Feb 19 '14 at 09:25
2

If you're are using framework 4.0 then entry in web.config ()

<configuration>
    <system.web>
        <pages validateRequest="false" />
    </system.web>
</configuration>

If you're using framework 4.5 then entry in web.config (requestValidationMode="2.0")

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" requestValidationMode="2.0"/>
</system.web>

Link

Community
  • 1
  • 1
Durgesh Pandey
  • 2,314
  • 4
  • 29
  • 43
1

This might not be the solution for your problem, but i was having same problem and solved it by checking for postback before binding data.

  (!IsPostBack)
{
  binddata(); //this was my gridview binding function
}
cb.sash
  • 11
  • 1
0

This error also occurs when there is another form on the page that does not contain runat = server. Please check if there is another form on the master page or the current page.