无法加载视图状态 [英] Failed to load view State

查看:93
本文介绍了无法加载视图状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!



我正在尝试更新gridview的行。当我点击编辑按钮时没有任何反应。当我再次点击它时,它会显示我的错误。



Hello!

I am trying to update the row of a gridview . When i click on edit button nothing happens. when i again click on it , it shows me this error.

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.





在我的网页上我正在调用此函数





on my pageload i am calling this function

Public Sub BindGrid()
        Dim cd As String = Session("usercd")
        Dim x As String = "select e.index_no , e.ref_no ,n.nature_detail as natureD,e.[subject] , e.outside_details,e.outside_copy_details from let_entry e "
        x += "inner join nature as n on n.nature_cd=nature_code "

        x += "where index_no like '%-D-%'"
        x += " and org_usr_code='" + cd + "'"
        x += "and let_no not in (select let_no from dispatch_det) order by 1 desc"
        Dim dt As New DataTable()
        dt = Dal.GettDS(x).Tables(0)
        GridView3.DataSource = dt
        GridView3.DataBind()







这些是活动






these are the events

Protected Sub GridView3_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView3.RowEditing
    GridView3.EditIndex = e.NewEditIndex

End Sub

Protected Sub GridView3_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView3.RowCancelingEdit
    e.Cancel = True
    GridView3.EditIndex = -1
End Sub

Protected Sub GridView3_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView3.RowUpdating
    Dim gvrow As GridViewRow = GridView3.Rows(e.RowIndex)
    Dim NatureCode As DropDownList = DirectCast(gvrow.FindControl("ddlNature"), DropDownList)
    Dim txtReferenceNo As TextBox = DirectCast(gvrow.FindControl("txtRefNo"), TextBox)
    Dim txtSubject As TextBox = DirectCast(gvrow.FindControl("txtSubject"), TextBox)
    Dim txtOutsideDetails As TextBox = DirectCast(gvrow.FindControl("txtOutsideDetails"), TextBox)
    Dim txtOutsideCopyDetail As TextBox = DirectCast(gvrow.FindControl("txtOutsideCopyDetails"), TextBox)
    Dim lblDisNo As Label = DirectCast(gvrow.FindControl("lblDisNo"), Label)

    Dim DisNo As String = lblDisNo.Text
    Dim Ncode As Int32 = NatureCode.SelectedValue
    Dim RefNo As String = txtReferenceNo.Text
    Dim Subj As String = txtSubject.Text
    Dim OutsideDetails As String = txtOutsideDetails.Text
    Dim OutsideCopyDetails As String = txtOutsideCopyDetail.Text

    Dim constring As String = ConfigurationManager.ConnectionStrings("patravaliConnectionString").ConnectionString
    Dim con As New SqlConnection(constring)
    Dim trns As SqlTransaction
    con.Open()
    trns = con.BeginTransaction()
    Dim x As String

    x = UpdateDetails(DisNo, RefNo, Ncode, Subj, OutsideDetails, OutsideCopyDetails, trns)
    Try
        If Val(x) > 0 Then
            trns.Commit()
        Else
            trns.Rollback()
        End If
    Catch ex As Exception
    Finally

        con.Close()
        BindGrid()
    End Try



End Sub

Public Function UpdateDetails(ByVal Disno As String, ByVal RefrenceNo As String, ByVal Naturecode As Int32, ByVal Subject As String, ByVal OutsideDetails As String, ByVal OutsideCopyDetails As String, ByVal trns As SqlTransaction) As String


    Dim update As String = "update let_entry set ref_no=@ref_no ,nature_code=@nature_cd, [subject]=@subject , outside_details=@outside_details, outside_copy_details=@outside_copy_details where index_no =@index_no"

    Dim cmd As New SqlCommand(update, trns.Connection)
    cmd.Transaction = trns
    cmd.Parameters.AddWithValue("@ref_no", RefrenceNo)
    cmd.Parameters.AddWithValue("@index_no", Disno)
    cmd.Parameters.AddWithValue("@nature_cd", Naturecode)
    cmd.Parameters.AddWithValue("@subject", Subject)
    cmd.Parameters.AddWithValue("@outside_details", OutsideDetails)
    cmd.Parameters.AddWithValue("@outside_copy_details", OutsideCopyDetails)

    UpdateDetails = cmd.ExecuteNonQuery().ToString()



End Function

推荐答案

完成整个讨论,看看你学到了什么: http://forums.asp.net/t/940975.aspx/4/10 [ ^ ]



读取评论作者:PhilM99。
Go through this whole discussion and see what you learn: http://forums.asp.net/t/940975.aspx/4/10[^]

Do read comment by PhilM99.


您应该向更新事件添加代码以检查事件中的行是否为itemtemplate或edittemplate。



ddlNature控件位于编辑模板内部,因此您需要首先检查它是否会解析。
You should add code to the update event to check if the row in event arg e is itemtemplate or edittemplate.

The ddlNature control is inside edit template so you need to check that first then it will resolve.


这篇关于无法加载视图状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆