This is a migrated thread and some comments may be shown as answers.

error when push edit button

3 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alfa
Top achievements
Rank 1
Alfa asked on 03 Aug 2011, 05:02 PM

hi,

My name is Francisco, I update 2010 Q2 to 2011 Q2 ASP NET and my grid don't work, before update working fine.

When i click edit button of a row, show me a error in the status bar of Internet Explorer version 8.

The error message is:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Can you help me please.

Regards....

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 08 Aug 2011, 04:20 PM
Hi Francisco Rios,

I assume the problem might be caused by a databinding issue. Please confirm if you are using simple or advanced data-binding. Issues like this one have been reported when using simple data-binding.

Best wishes,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Alfa
Top achievements
Rank 1
answered on 08 Aug 2011, 11:04 PM

Hi,

i tought use both binding.

this is my code. can you check please.

Regards...


Imports System.Data
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Imports System.Globalization
Imports System.Threading
Imports System.Net
  
Partial Class Inventarios_Ciclicos_Captura_Existencias
    Inherits System.Web.UI.Page
  
    Private Function Validador(ByVal Editor As GridNumericColumnEditor, ByVal Nombre As String) As RequiredFieldValidator
  
        Dim validator As RequiredFieldValidator = New RequiredFieldValidator
  
        Editor.NumericTextBox.ID = Nombre + "_Validacion"
        validator.ControlToValidate = Editor.NumericTextBox.ID
        validator.ErrorMessage = "*"
  
        Return validator
    End Function
  
    Private Function Crear_Tabla_Productos(ByVal ID As String) As DataTable
        Dim tblProductos As New DataTable("Productos")
        tblProductos.Columns.Add("Producto", GetType(Short))
        tblProductos.Columns.Add("NomProducto", GetType(String))
        tblProductos.Columns.Add("Existencia_Fisica", GetType(Integer))
        tblProductos.Columns.Add("Existencia_SAI", GetType(Integer))
        tblProductos.Columns.Add("Unidad", GetType(String))
  
        Dim PrimaryKeyColumns(0) As DataColumn
        PrimaryKeyColumns(0) = tblProductos.Columns("Producto")
        tblProductos.PrimaryKey = PrimaryKeyColumns
  
            Dim Util1 As New Utilerias
            Using MiBase As New SqlConnection(Util1.Obtener_Conexion("DB_Reportes"))
  
                MiBase.Open()
  
            'Cargo los productos en la tabla temporal
            Dim SQL As String = " Select a.*, b.desc_prod As NomProducto From Ciclicos_Det a" + _
                                " Left Join Producto b On a.cve_prod = b.cve_prod And a.Base_Datos = b.Base_Datos" + _
                                " Where Id_Interno = '" + ID + "' And Fecha_Captura Is Null" + _
                                " Order By b.desc_prod"
  
            Dim dsDatos As DataSet
            dsDatos = Util1.RegresaRegistros_DataSet(MiBase, SQL, 0)
  
            Dim drDatos As DataRow
            For Each drDatos In dsDatos.Tables(0).Rows
                Dim Renglon As DataRow = tblProductos.NewRow
                Renglon("Producto") = drDatos("cve_prod")
                Renglon("NomProducto") = drDatos("NomProducto")
                Renglon("Existencia_Fisica") = drDatos("Existencia_Fisica")
                tblProductos.Rows.Add(Renglon)
            Next
            tblProductos.AcceptChanges()
  
        End Using
  
        Return tblProductos
    End Function
  
  
    'Private Function Obtener_Existencia_SAI(ByVal Producto As String, ByVal Bodega As String) As Double
  
    '    Dim SQL As String = " Select Sum(existencia) As Existencia From Existe" + _
    '                        " Where cve_prod = '" + Producto + "' And lugar = '" + Bodega + "'"
  
  
    '    Dim Util1 As New Utilerias
    '    Using MiBase As New SqlConnection(Util1.Obtener_Conexion("DB_Reportes"))
  
    '        MiBase.Open()
  
    '        Dim dtDatos As SqlDataReader
    '        dtDatos = Util1.RegresaRegistros_DataReader(MiBase, SQL, 0)
  
    '        If dtDatos.Read Then
    '            Return IIf(IsDBNull(dtDatos("Existencia")), 0, dtDatos("Existencia"))
    '        Else
    '            Return 0
    '        End If
  
    '    End Using
  
    'End Function
  
    Private Function Cargar_Existencia_SAI(ByVal TblCiclicos As DataTable) As DataTable
        Dim dtExistencias As DataTable = TblCiclicos
        Dim drExistencias As DataRow
  
        'Dim MiProxy As WebProxy = New WebProxy()
        'MiProxy.Credentials = CredentialCache.DefaultCredentials
  
        Dim ws As New ws_reportes.Datos_Reportes
        'ws.Proxy = MiProxy
  
  
        For Each drExistencias In dtExistencias.Rows
            If Not IsDBNull(drExistencias("Existencia_Fisica")) Then
                drExistencias.BeginEdit()
                Dim Mensaje As String
                drExistencias("Existencia_SAI") = ws.Obtener_Existencia_SAI(Me.hfBD.Value, drExistencias("Producto"), Me.txtBodega.Text, Mensaje)
                drExistencias.EndEdit()
            End If
        Next
        dtExistencias.AcceptChanges()
  
        Return dtExistencias
    End Function
  
    Private Function Muestra_Informacion_Encabezado(ByVal ID As String) As Boolean
  
        If ID = "" Then
            lblMensajeId.Text = "Folio no válido."
            Me.pgMensaje.Selected = True
            Return False
        End If
  
        Thread.CurrentThread.CurrentCulture = New CultureInfo("es-MX")
  
        Dim SQL As String = " Select * From Ciclicos_Enc" + _
                            " Where Id_Interno = '" + ID + "'"
  
        Dim Util1 As New Utilerias
        Dim MiBase As New SqlConnection(Util1.Obtener_Conexion("DB_Reportes"))
        Dim dsDatos As DataSet
        dsDatos = Util1.RegresaRegistros_DataSet(MiBase, SQL, 0)
  
        If dsDatos.Tables(0).Rows.Count > 0 Then
            txtFolio.Text = dsDatos.Tables(0).Rows(0)("Folio")
            txtBodega.Text = dsDatos.Tables(0).Rows(0)("Bodega").ToString.TrimEnd
            Me.txtFecha.Text = CDate(dsDatos.Tables(0).Rows(0)("Fecha")).ToShortDateString
  
            txtFolio2.Text = dsDatos.Tables(0).Rows(0)("Folio")
            txtBodega2.Text = dsDatos.Tables(0).Rows(0)("Bodega").ToString.TrimEnd
            Me.txtFecha2.Text = CDate(dsDatos.Tables(0).Rows(0)("Fecha")).ToShortDateString
  
            Dim lnkUsuario As HyperLink = CType(Me.UcEncabezado1.FindControl("lnkUsuario"), HyperLink)
            lnkUsuario.Text = dsDatos.Tables(0).Rows(0)("Responsable")
  
            Me.hfBD.Value = dsDatos.Tables(0).Rows(0)("Base_Datos")
  
            If dsDatos.Tables(0).Rows(0)("Liberado") <> 0 Then
                lblMensajeId.Text = "El Folio " + dsDatos.Tables(0).Rows(0)("Folio").ToString + " ya no tiene movimientos pendientes por capturar."
                Me.pgMensaje.Selected = True
                Return False
            End If
  
        Else
            lblMensajeId.Text = "Folio no válido."
            Me.pgMensaje.Selected = True
            Return False
        End If
  
        Return True
  
    End Function
  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'hdtoSaveData.Value = "xxx"
        If Not Page.IsPostBack Then
            'Me.btnGuardar.Attributes.Add("onclick", "return validar_datos();")
  
            Dim ID As String
            If Not Me.Page.Request("ID") Is Nothing Then
                ID = CType(Me.Page.Request("ID"), String)
            Else
                ID = ""
            End If
  
            If Muestra_Informacion_Encabezado(ID) Then
                Session("GridProductos") = Crear_Tabla_Productos(ID)
            End If
  
        End If
  
    End Sub
  
    Protected Sub grdProductos_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdProductos.ItemCommand
  
        Try
  
            If e.CommandName = RadGrid.InitInsertCommandName Then
                Session("Editar_Producto") = True
                Session("Actualizar_Producto") = True
            ElseIf e.CommandName = RadGrid.EditCommandName Then
                Session("Editar_Producto") = True
                Session("Actualizar_Producto") = Nothing
  
                Me.grdProductos.DataSource = Session("GridProductos")
            ElseIf e.CommandName = RadGrid.CancelCommandName Then
                Session("Actualizar_Producto") = True
                Session("Editar_Producto") = Nothing
  
            ElseIf e.CommandName = RadGrid.UpdateCommandName Then
  
                Dim dtProductos As DataTable = Session("GridProductos")
  
                Dim i As Short
                For i = 0 To Me.grdProductos.EditIndexes.Count - 1
  
                    Dim dataItem As GridDataItem = CType(grdProductos.MasterTableView.Items(grdProductos.EditIndexes(i)), GridDataItem)
                    Dim editItem As GridEditableItem = IIf(dataItem.OwnerTableView.EditMode = GridEditMode.InPlace, CType(dataItem, GridEditableItem), CType(dataItem.EditFormItem, GridEditableItem))
                    Dim mng As GridEditManager = editItem.EditManager
  
                    Dim editorTextKey As String = Nothing
  
                    Dim column As GridColumn
                    For Each column In dataItem.OwnerTableView.Columns
  
                        If TypeOf column Is IGridEditableColumn Then
                            Dim editedColumn As IGridEditableColumn = CType(column, IGridEditableColumn)
  
                            If Not TypeOf editedColumn Is GridTemplateColumn Then
                                Dim editor As IGridColumnEditor = mng.GetColumnEditor(editedColumn)
  
                                'Dim editorType As String = editor.ToString
                                Dim editorText As String = Nothing
  
                                If TypeOf editor Is GridTextColumnEditor Then
                                    editorText = (CType(editor, GridTextColumnEditor)).Text
                                ElseIf TypeOf editor Is GridDropDownColumnEditor Then
                                    editorText = (CType(editor, GridDropDownColumnEditor)).SelectedValue
                                End If
  
  
                                Try
  
                                    'No permito que la llave se actualice si no hasta al final ya que se pierde referencia con el registro
                                    If column.UniqueName <> "Producto" Then
                                        Dim changedRows As DataRow() = dtProductos.Select("Producto = " + editItem.OwnerTableView.DataKeyValues(editItem.ItemIndex)("Producto").ToString)
                                        changedRows(0)(column.UniqueName) = editorText
                                    Else
                                        editorTextKey = CType(editor, GridTextBoxColumnEditor).Text
                                    End If
  
                                Catch ex As Exception
                                    grdProductos.Controls.Add(New LiteralControl("No se puede actualizar el producto. Razón: " + ex.Message))
                                End Try
  
                            End If
  
                        End If
  
                    Next
  
                    'Actualizo la llave
                    Dim changedRowsKey As DataRow() = dtProductos.Select("Producto = " + editItem.OwnerTableView.DataKeyValues(editItem.ItemIndex)("Producto").ToString)
                    changedRowsKey(0)("Producto") = editorTextKey
  
                Next
  
  
                dtProductos.AcceptChanges()
                Session("GridProductos") = dtProductos
  
                Session("Editar_Producto") = Nothing
                Session("Actualizar_Producto") = True
  
  
            ElseIf e.CommandName = RadGrid.PerformInsertCommandName Then
  
                Dim dtProductos As DataTable = Session("GridProductos")
                Dim newRow As DataRow = dtProductos.NewRow
  
  
                Dim insertItem As GridEditableItem = Me.grdProductos.MasterTableView.GetInsertItem()
                Dim mng As GridEditManager = insertItem.EditManager
                Dim newValues As Hashtable = New Hashtable
  
                For Each column As GridColumn In insertItem.OwnerTableView.Columns
                    If TypeOf column Is IGridEditableColumn Then
                        Dim editableCol As IGridEditableColumn = (CType(column, IGridEditableColumn))
                        If editableCol.IsEditable Then
                            Dim editor As IGridColumnEditor = mng.GetColumnEditor(editableCol)
                            Dim editorText As String = "unknown"
                            Dim editorValue As Object = Nothing
                            If TypeOf editor Is GridTextColumnEditor Then
                                editorText = (CType(editor, GridTextColumnEditor)).Text
                                editorValue = (CType(editor, GridTextColumnEditor)).Text
                            End If
                            If TypeOf editor Is GridBoolColumnEditor Then
                                editorText = (CType(editor, GridBoolColumnEditor)).Value.ToString
                                editorValue = (CType(editor, GridBoolColumnEditor)).Value
                            End If
                            If TypeOf editor Is GridDropDownColumnEditor Then
                                editorText = (CType(editor, GridDropDownColumnEditor)).SelectedText + "; " + (CType(editor, GridDropDownColumnEditor)).SelectedValue
                                editorValue = (CType(editor, GridDropDownColumnEditor)).SelectedValue
                            End If
                            'If TypeOf editor Is GridDateTimeColumn Then
                            '    editorText = (CType(editor, GridDateTimeColumn)).DataFormatString + "; " + (CType(editor, GridDateTimeColumn)).DataFormatString
                            '    editorValue = (CType(editor, GridDateTimeColumn)).DataFormatString
                            'End If
                            Try
                                newRow(column.UniqueName) = editorValue
                            Catch ex As Exception
                                grdProductos.Controls.Add(New LiteralControl("No se puede agregar el producto. Razón: " + ex.Message))
                            End Try
                        End If
                    End If
                Next
  
                Session("Editar_Producto") = Nothing
                Session("Actualizar_Producto") = Nothing
  
                Try
                    dtProductos.Rows.Add(newRow)
                Catch ex As Exception
                    grdProductos.Controls.Add(New LiteralControl("No se puede agregar el producto. Razón: " + ex.Message))
                End Try
  
  
                Session("GridProductos") = dtProductos
                Me.grdProductos.DataSource = Session("GridProductos")
            ElseIf e.CommandName = RadGrid.DeleteCommandName Then
  
                Dim ID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Producto").ToString()
                Dim dtProductos As DataTable = Session("GridProductos")
                If Not dtProductos.Rows.Find(ID) Is Nothing Then
                    dtProductos.Rows.Find(ID).Delete()
                    dtProductos.AcceptChanges()
                    Session("GridProductos") = dtProductos
                End If
  
                Session("Editar_Producto") = Nothing
                Session("Actualizar_Producto") = True
  
            End If
  
        Catch exception As Exception
            Dim Util1 As New Utilerias
            Call Util1.Agregar_Log_Errores(Session("Usuario"), "Captura_Existencias", 0, exception.Message, "grdProductos_ItemCommand")
        End Try
  
    End Sub
  
    Protected Sub grdProductos_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grdProductos.ItemCreated
        Try
            If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
                Dim item As GridEditableItem = CType(e.Item, GridEditableItem)
                Dim editor As GridNumericColumnEditor = CType(item.EditManager.GetColumnEditor("Existencia_Fisica"), GridNumericColumnEditor)
                Dim cell As TableCell = CType(editor.NumericTextBox.Parent, TableCell)
                cell.Controls.Add(Validador(editor, "Existencia_Fisica"))
            End If
        Catch exception As Exception
            Dim Util1 As New Utilerias
            Call Util1.Agregar_Log_Errores(Session("Usuario"), "Captura_Existencias", 0, exception.Message, "grdProductos_ItemCommand")
        End Try
  
    End Sub
  
  
    Protected Sub grdProductos_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grdProductos.ItemDataBound
        Try
            If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then
                Dim edititem As GridEditableItem = CType(e.Item, GridEditableItem)
  
                Dim txtProducto As TextBox = CType(edititem("Producto").Controls(0), TextBox)
                txtProducto.Width = Unit.Pixel(50)
                'txtProducto.Enabled = False
                txtProducto.ReadOnly = True
                txtProducto.Font.Size = 9
  
  
                Dim txtExistenciaFisica As RadNumericTextBox = CType(edititem("Existencia_Fisica").Controls(0), RadNumericTextBox)
                txtExistenciaFisica.Width = Unit.Pixel(100)
                txtExistenciaFisica.Font.Size = 9
  
                Dim txtNomProducto As TextBox = CType(edititem("NomProducto").Controls(0), TextBox)
                txtNomProducto.Width = Unit.Pixel(220)
                txtNomProducto.Font.Size = 9
                'txtNomProducto.Enabled = False
                txtNomProducto.ReadOnly = True
                txtNomProducto.MaxLength = 100
  
            End If
        Catch exception As Exception
            Dim Util1 As New Utilerias
            Call Util1.Agregar_Log_Errores(Session("Usuario"), "Captura_Existencias", 0, exception.Message, "grdProductos_ItemCommand")
        End Try
  
    End Sub
  
    Protected Sub grdProductos_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdProductos.NeedDataSource
  
        Try
            If (Session("Editar_Producto") Is Nothing And Not Page.IsPostBack) Then
                Me.grdProductos.DataSource = Session("GridProductos")
            ElseIf Not Session("Actualizar_Producto") = Nothing Then
                Me.grdProductos.DataSource = Session("GridProductos")
                Session("Actualizar_Producto") = Nothing
            End If
        Catch exception As Exception
            Dim Util1 As New Utilerias
            Call Util1.Agregar_Log_Errores(Session("Usuario"), "Captura_Existencias", 0, exception.Message, "grdProductos_ItemCommand")
        End Try
  
    End Sub
  
    Protected Sub btnGuardar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGuardar.Click
  
        Me.txtObservaciones2.Text = Me.txtObservaciones.Text
  
        Dim dtCiclicos As DataTable = CType(Session("GridProductos"), DataTable)
        Session("GridProductos") = Cargar_Existencia_SAI(dtCiclicos)
  
        Me.grdProductos2.DataSource = Session("GridProductos")
        Me.grdProductos2.DataBind()
  
        Me.pgMensajeGuardar.Selected = True
  
        If Not Me.Page.Request("ID") Is Nothing Then
            ID = CType(Me.Page.Request("ID"), String)
        Else
            ID = ""
        End If
  
  
        Dim Util1 As New Utilerias
        Using MiBase As New SqlConnection(Util1.Obtener_Conexion("DB_Reportes"))
  
            MiBase.Open()
  
            Dim Transaccion As SqlTransaction
            Transaccion = MiBase.BeginTransaction("Transacion")
  
            Try
  
                Dim dtProductos As DataTable = CType(Session("GridProductos"), DataTable)
                Dim drProductos As DataRow
                For Each drProductos In dtProductos.Rows
                    If Not IsDBNull(drProductos("Existencia_Fisica")) Then
                        Dim cmdCiclicosDet As New SqlCommand()
                        cmdCiclicosDet.Connection = MiBase
                        cmdCiclicosDet.Transaction = Transaccion
                        cmdCiclicosDet.CommandType = CommandType.StoredProcedure
                        cmdCiclicosDet.CommandText = "spUpd_Ciclicos_Det"
                        cmdCiclicosDet.Parameters.Add("@ID", SqlDbType.VarChar, 36)
                        cmdCiclicosDet.Parameters.Add("@Producto", SqlDbType.VarChar, 10)
                        cmdCiclicosDet.Parameters.Add("@Existencia_Fisica", SqlDbType.Int)
                        cmdCiclicosDet.Parameters.Add("@Existencia_Real", SqlDbType.Int)
  
                        cmdCiclicosDet.Parameters("@ID").Value = ID
                        cmdCiclicosDet.Parameters("@Producto").Value = drProductos("Producto")
                        cmdCiclicosDet.Parameters("@Existencia_Fisica").Value = drProductos("Existencia_Fisica")
                        cmdCiclicosDet.Parameters("@Existencia_Real").Value = drProductos("Existencia_SAI")
  
                        cmdCiclicosDet.Prepare()
                        cmdCiclicosDet.ExecuteNonQuery()
                    End If
                Next
  
  
                Dim cmdCiclicosEnc As New SqlCommand
                cmdCiclicosEnc.Connection = MiBase
                cmdCiclicosEnc.Transaction = Transaccion
                cmdCiclicosEnc.CommandType = CommandType.StoredProcedure
                cmdCiclicosEnc.CommandText = "spUpd_Ciclicos_Enc"
                cmdCiclicosEnc.Parameters.Add("@ID", SqlDbType.VarChar, 36)
                cmdCiclicosEnc.Parameters.Add("@Observaciones", SqlDbType.Text)
  
                cmdCiclicosEnc.Parameters("@ID").Value = ID
                cmdCiclicosEnc.Parameters("@Observaciones").Value = Me.txtObservaciones.Text
                cmdCiclicosEnc.ExecuteNonQuery()
  
                Transaccion.Commit()                
  
                'Response.Write("Su operación se realizo con exito.")
            Catch exSQL As SqlException
                lblMensaje.text = exSQL.Message
                Transaccion.Rollback()
            Catch ex As Exception
                lblMensaje.text = ex.Message
                Transaccion.Rollback()
            End Try
  
        End Using
  
        pnlMensaje.visible = True
  
    End Sub
  
End Class
0
Pavlina
Telerik team
answered on 09 Aug 2011, 04:19 PM
Hello Francisco Rios,

Note that you should not mix simple databinding with advanced databinding. Simple data-binding with the DataBind() method can be used in simple scenarios which does not require complex operations such as editing, grouping, paging etc. So, in your case I would suggest you to use Advanced Data-binding (using NeedDataSource event) to populate the grid and see if it makes any difference.

All the best,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Alfa
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Alfa
Top achievements
Rank 1
Share this question
or