title: Cancel Editing during Gridview_RowEditing()?
body: <p>I want to cancel <em>row editing</em> during <code>RowEditing</code> if the current user doesn't have the necessary permissions.</p>
  
  <p>This is what <code>RowEditing</code> looks like:</p>
  
  <pre><code>protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
  {
      string user = GetCurrentUser();
      if (user == string.Empty)
      {
          /* Show message alert */
          return;
      }
      GridView.EditIndex = e.NewEditIndex;
      BindData();
  }
  </code></pre>
  
  <p>This cancels the <em>Update</em> and the column continues with the <em>Edit</em> link. But if I click <em>Edit</em> again, it will show this error:</p>
  
  <blockquote>
    <p>Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.</p>
  </blockquote>
  
  <p>I assume it has to with hiding controls before a postback is made.</p>
  
  <p>So my question is, how do I avoid this?</p>
  
  <p>I also tried setting <code>GridView.EditIndex = -1</code>, but I get the same results:</p>
  
  <pre><code>protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
  {
      GridView.EditIndex = e.NewEditIndex;
      BindData();
      string user = GetCurrentUser();
      if (user == string.Empty)
      {
          /* Show message alert */
          GridView.EditIndex = -1;
          BindData();
          return;
  }
  </code></pre>