Visualizzazione dei risultati da 1 a 8 su 8

Hybrid View

  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2001
    Messaggi
    1,482

    Strano errore: Failed to load viewstate...

    Ecco l'errore:

    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.
    Ecco il codice:

    codice:
        Private Sub Dtg_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Dtg.PreRender
            Dim DtgItem As DataGridItem
            For Each DtgItem In Me.Dtg.Items
                If BlnIsRicerca Then
                    Dim TabPerc As New DataTable
                    TabPerc = DirectCast(DirectCast(sender, DataGrid).DataSource, DataView).Table
                    If DtgItem.ItemType = ListItemType.AlternatingItem Or DtgItem.ItemType = ListItemType.SelectedItem Or DtgItem.ItemType = ListItemType.Item Or DtgItem.ItemType = ListItemType.EditItem Then
                        BlnPrintPercorso = False
                        StrPercorso = DirectCast(TabPerc.Rows(IncItem)("gruppo"), String).ToUpper & " > " & DirectCast(TabPerc.Rows(IncItem)("ramo"), String).ToUpper & " > " & DirectCast(TabPerc.Rows(IncItem)("categoria"), String).ToUpper
                        If IncItem = 0 Then
                            Session("CurrPerc") = StrPercorso
                            BlnPrintPercorso = True
                        Else
                            If StrPercorso <> Session("CurrPerc") Then
                                Session("CurrPerc") = StrPercorso
                                BlnPrintPercorso = True
                            Else
                                BlnPrintPercorso = False
                            End If
                        End If
                        If BlnPrintPercorso Then
                            Response.Write(IncItem & ") " & Session("CurrPerc") & "
    ")
                            Dim NewItem As New DataGridItem(IncItem, IncItem, ListItemType.Item)
                            NewItem.ID = "NewRow_" & Me.Dtg.CurrentPageIndex & "_" & Me.IncItem
                            Dim NewTd As New TableCell
                            NewTd.ColumnSpan = 4
                            NewTd.Text = Session("CurrPerc")
                            NewTd.Width = New Unit("100%")
                            With NewTd
                                .BackColor = Color.FromName("#FFFFFF")
                                .Height = New Unit(30)
                                .HorizontalAlign = HorizontalAlign.Left
                            End With
                            NewItem.Cells.Add(NewTd)
                            Dim Tab As New Table
                            Tab = CType(Me.Dtg.Controls(0), Table)
                            Tab.Rows.AddAt(IncItem + IncItemBis + 2, NewItem) 
                            IncItemBis = IncItemBis + 1
                        End If
                        IncItem = IncItem + 1
                    End If
                End If
            Next
        End Sub
    è l'evento prerender di un datagrid. Ho provato a gestire il tutto negli eventi itemcreated e itemdatabound me il risultato è lo stesso.

    Se commento la riga in rosso la pagina viene caricata correttamente, ma ovvimanete non mi aggiunge le righe al datagrid.

    Da notare che l'errore avviene quando eseguo un postback della pagina, al primo caricamento infatti tutto funiona egregiamente.

    sto impazzendo...

    grazie

    ciao

    Hey hey, my my Rock and roll can never die!

  2. #2
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,881
    azz scusatemi se rispolvero ma mi è appena uscito lo stesso problema.
    Se disabilito il viewstate per i controlli creati dinamicamente (come suggerito più sopra) cosa succede a quei controlli? Intendo il fatto che un controllo sia escluso dalla gestione del viewstate può causare qualche failure nel successivo funzionamento di quei controlli nella maschera?

    Tra l'altro, ora che vedo, io di controlli creati dinamicamente nella pagina non ne ho, ho soltanto una multiview a cui cambio l'activeviewindex e detailsview e formview a cui cambio il mode da codice... ???
    Ultima modifica di supermac; 03-03-2015 a 12:40
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  3. #3
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,881
    risolto, nel pageLoad è bastato estrarre alcune istruzioni da un if not ispostback e tutto è tornato a funzionare...
    il viewstate comunque è un brutto cliente :-)
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.