What is the purpose of EnableEventValidation and how does it work?
<pre><code>    &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" onrowediting="GridView1_RowEditing"&gt;
        &lt;Columns&gt;
            &lt;asp:TemplateField&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" /&gt;
                    &lt;asp:Label ID="lblFirstColumn" runat="server" Text='&lt;%# Eval("FirstColumn") %&gt;'&gt;&lt;/asp:Label&gt;
                &lt;/ItemTemplate&gt;
                &lt;EditItemTemplate&gt;
                    &lt;asp:Label ID="lblEditMode" runat="server" Text="This is Edit mode"&gt;&lt;/asp:Label&gt;
                &lt;/EditItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
        &lt;/Columns&gt;
    &lt;/asp:GridView&gt;


protected void Page_Load(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("FirstColumn", typeof(int));
    dt.Rows.Add(100);

    GridView1.DataSource = dt;
    if (!IsPostBack)
        GridView1.DataBind();
}

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView1.EditIndex = e.NewEditIndex;
    GridView1.DataBind();

}
</code></pre>

<p>If I change <code>if (!IsPostBack) GridView1.DataBind();</code> to <code>GridView1.DataBind();</code> and try to put GridView into Edit mode by clicking btnEdit, then I get the exception:</p>

<blockquote>
  <p>Invalid postback or callback argument.
  Event validation is enabled using
  
  in configuration or &lt;%@ Page
  EnableEventValidation="true" %> in a
  page.  For security purposes, this
  feature verifies that arguments to
  postback or callback events originate
  from the server control that
  originally rendered them.  If the data
  is valid and expected, use the
  ClientScriptManager.RegisterForEventValidation
  method in order to register the
  postback or callback data for
  validation.</p>
</blockquote>

<p>But if I set <code>EnableEventValidation</code> to <code>false</code>, then <code>GridView1</code> won’t enter edit mode ( ie - <code>GridView1_RowEditing</code> doesn’t get called ). </p>

<p>BTW – same problem also occurs with other databound controls ( DataList, DetailsView )</p>

<blockquote>
  <p>Page. EnableEventValidation gets or
  sets a value indicating whether the
  page validates postback and callback
  events. When the EnableEventValidation
  property is set to true, ASP.NET
  validates that a control event
  originated from the user interface
  that was rendered by that control. A
  control registers its events during
  rendering and then validates the
  events during postback or callback
  handling.</p>
</blockquote>

<p>a) Why must postback and callback events be evaluated? and how exactly does evaluation happen?</p>

<p>b) Why would calling <code>GridView1.Databind()</code> on each postback cause exception when trying to put it into <code>edit</code> mode? </p>

<p>c) I also don’t see any reasons why disabling <code>EnableEventValidation</code> prevents GridView from entering <code>edit</code> mode?! Thus why did </p>

<p>thank you</p>
