aspx gridview があり、コード ビハインドから作成した 2 つのボタンがあります。それらは編集と更新であり、コマンドはそれぞれ「編集」と「更新」です。編集ボタンをクリックすると、コードに従って更新ボタンも有効になります(編集ボタンをクリックして、行のチェックボックスの数を有効にします)。実際には機能しませんが、次のようなエラーが発生します。
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&t=6119e399:237
Error$create ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…FVxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&t=6119e399:237
Sys$WebForms$PageRequestManager$_createPageRequestManagerServerError ScriptResource.axd?d=7CCl932sdoNYgGI8lOxtB8kESr24em-vtPyWNc_v1_wD6b2GgTVWjP…QcN8ofM_7MSrJt5JPbNycIyF7ZMnid435yQKsqw0E4wzsq_yDDUHNjPqpn0&t=6119e399:656
Sys$WebForms$PageRequestManager$_parseDelta ScriptResource.axd?d=7CCl932sdoNYgGI8lOxtB8kESr24em-vtPyWNc_v1_wD6b2GgTVWjP…cN8ofM_7MSrJt5JPbNycIyF7ZMnid435yQKsqw0E4wzsq_yDDUHNjPqpn0&t=6119e399:1534
Sys$WebForms$PageRequestManager$_onFormSubmitCompleted ScriptResource.axd?d=7CCl932sdoNYgGI8lOxtB8kESr24em-vtPyWNc_v1_wD6b2GgTVWjP…cN8ofM_7MSrJt5JPbNycIyF7ZMnid435yQKsqw0E4wzsq_yDDUHNjPqpn0&t=6119e399:1314
(anonymous function) ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…RFVxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&t=6119e399:47
(anonymous function) ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…VxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&t=6119e399:3484
Sys$Net$WebRequest$completed ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…VxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&t=6119e399:6373
Sys$Net$XMLHttpExecutor._onReadyStateChange ScriptResource.axd?d=s633GAD3X_M-LlZYiT3qBN0z6qIwAPEBIp-UIaJwC1RmW46ky4uU_K…VxRGlhX1aNlsf8k9x5vWwmLMiniFjzCpYiBd1nZ4CsPRcFgOOZfIhN5YF0&t=6119e399:5993
何が問題で、どうすれば解決できますか?
2 つのボタン
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 >= 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)
EDITボタンからの不具合原因:想定