title: Asp.Net Ajax Error: Uncaught Sys.WebForms.PageRequestManagerServerErrorException:
body: <p>I have aspx gridview and i have two buttons that i created from code behind. they are Edit &amp; Update and their commands are 'Edit' &amp;'Update'respectively. when I click Edit Button it enables (Click on the edit button enable number of checkbox in the row) the Update Button too according to the code. Although in reality it doesnt work and it gives an error as follow:</p>
  
  <pre><code>Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: 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. ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…FVxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&amp;t=6119e399:237
  Error$create ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…FVxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&amp;t=6119e399:237
  Sys$WebForms$PageRequestManager$_createPageRequestManagerServerError ScriptResource.axd?d=7CCl932sdoNYgGI8lOxtB8kESr24em-vtPyWNc_v1_wD6b2GgTVWjP…QcN8ofM_7MSrJt5JPbNycIyF7ZMnid435yQKsqw0E4wzsq_yDDUHNjPqpn0&amp;t=6119e399:656
  Sys$WebForms$PageRequestManager$_parseDelta ScriptResource.axd?d=7CCl932sdoNYgGI8lOxtB8kESr24em-vtPyWNc_v1_wD6b2GgTVWjP…cN8ofM_7MSrJt5JPbNycIyF7ZMnid435yQKsqw0E4wzsq_yDDUHNjPqpn0&amp;t=6119e399:1534
  Sys$WebForms$PageRequestManager$_onFormSubmitCompleted ScriptResource.axd?d=7CCl932sdoNYgGI8lOxtB8kESr24em-vtPyWNc_v1_wD6b2GgTVWjP…cN8ofM_7MSrJt5JPbNycIyF7ZMnid435yQKsqw0E4wzsq_yDDUHNjPqpn0&amp;t=6119e399:1314
  (anonymous function) ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…RFVxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&amp;t=6119e399:47
  (anonymous function) ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…VxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&amp;t=6119e399:3484
  Sys$Net$WebRequest$completed ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…VxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&amp;t=6119e399:6373
  Sys$Net$XMLHttpExecutor._onReadyStateChange ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…VxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&amp;t=6119e399:5993
  </code></pre>
  
  <p>what Should Be the Problem and How do i Solve it?</p>
  
  <p>two buttons</p>
  
  <pre><code> Dim btn2 As New Button()
              btn2.ID = "btn2"
              btn2.Width = "50"
              btn2.Text = "Update"
              btn2.CssClass = "AdminPageBtn"
              btn2.CommandName = "Update"
              btn2.CommandArgument = "Update"
              btn2.Enabled = True
  
              'If (nMonth &gt;= intCurrentMonth) And (nYear = intCurrentYear) Then
              '    btn2.Enabled = True
              'End If
  
              e.Row.Cells(e.Row.Cells.Count - 1).Controls.Add(btn2)
  
              Dim btn1 As New Button()
              btn1.ID = "btn1"
              btn1.Width = "50"
              btn1.Text = "Edit"
              btn1.CssClass = "AdminPageBtn"
              btn1.CommandName = "Edit"
              btn1.CommandArgument = "Edit"
              btn1.Enabled = True
  
  
      e.Row.Cells(e.Row.Cells.Count - 1).Controls.Add(btn1)
  </code></pre>
  
  <p>Problem causes from EDIT button : assumption</p>