ClientScriptManager.RegisterForEventValidation, asp.net, Vb.Net, VS2005 problem

Posted by: ronan2009 on 10 September 2017, 11:29 am EST

  • Posted 10 September 2017, 11:29 am EST

    Hi, 

    I'm facing a problem with an ajax enabled web page, I have created two template columns which holds image buttons in a C1WebGrid component, below is the code for the page, aspx.vb and error message:

     

    Invalid
    postback or callback argument.  Event validation is enabled using
    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.  aspx.vb Page Code   Partial Class Departments2    Inherits System.Web.UI.Page     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load                         Dim AD As New Data.SqlClient.SqlDataAdapter        Dim DS As New Data.DataSet         Dim conn As New Data.SqlClient.SqlConnection        Dim comm As New Data.SqlClient.SqlCommand         conn.ConnectionString = ConfigurationManager.ConnectionStrings("HRSystemConnectionString").ConnectionString        conn.Open()         comm.Connection = conn        Dim Sql As String        Sql = "SELECT * FROM Departments"         comm.CommandText = Sql        comm.CommandType = Data.CommandType.Text         AD.SelectCommand = comm        AD.Fill(DS)        Me.C1WebGrid1.DataSource = DS        Me.C1WebGrid1.DataBind()        conn.Close()     End Sub     Protected Sub
    ImageButton1_Click(ByVal sender As Object, ByVal e As
    System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click        Response.Redirect("NewDepartments2.aspx")    End Sub     Protected Sub
    C1WebGrid1_ItemCommand(ByVal sender As Object, ByVal e As
    C1.Web.C1WebGrid.C1CommandEventArgs) Handles C1WebGrid1.ItemCommand        If (e.CommandName = "Edit") Then            Session("DeptID") = e.Item.Cells(0).Text            Response.Redirect("NewDepartments2.aspx")        ElseIf (e.CommandName = "Delete1") Then            Dim AD As New Data.SqlClient.SqlDataAdapter            Dim DS As New Data.DataSet             Dim conn As New Data.SqlClient.SqlConnection            Dim comm As New Data.SqlClient.SqlCommand             conn.ConnectionString = ConfigurationManager.ConnectionStrings("HRSystemConnectionString").ConnectionString            conn.Open()             comm.Connection = conn            Dim Sql As String            Sql = "DELETE FROM Departments WHERE DeptID =" & e.Item.Cells(0).Text             comm.CommandText = Sql            comm.CommandType = Data.CommandType.Text             comm.ExecuteNonQuery()            conn.Close()            Response.Redirect("~Departments2.aspx")          End If    End Sub     Protected Sub C1WebGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1WebGrid1.PreRender            End Sub     Protected Sub C1WebGrid1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1WebGrid1.Init        ' Define the name and type of the client script on the page.        Dim csname As String = "OnSubmitScript"        Dim cstype As Type = Me.GetType()         ' Get a ClientScriptManager reference from the Page class.        Dim cs As ClientScriptManager = Page.ClientScript        Dim i As Integer        For i = 0 To C1WebGrid1.Items.Count - 1            cs.RegisterForEventValidation(C1WebGrid1.Items.Item(i).Cells(4).FindControl("ImageButton2").ClientID)            cs.RegisterForEventValidation(C1WebGrid1.Items.Item(i).Cells(5).FindControl("ImageButton3").ClientID)        Next    End SubEnd Class     departments.aspx code    <%@
    Page Language="VB" MasterPageFile="~/MasterPage.master"
    AutoEventWireup="false" CodeFile="Departments2.aspx.vb"
    Inherits="Departments2" title="Untitled Page" %> <%@ Register Assembly="C1.Web.C1WebGrid.2, Version=2.1.20073.111, Culture=neutral, PublicKeyToken=589f1fc067ff4031"    Namespace="C1.Web.C1WebGrid" TagPrefix="C1WebGrid" %>         
               
                  
               
     
                                                                                                   
    HeaderText="DepartmentCode" SortExpression="DepartmentCode">                                                                                                                                       
    CommandName="Delete1" ImageUrl="~/Images/delete.bmp" />               
               
           
       
     

     

  • Replied 10 September 2017, 11:29 am EST

     I wonder what is the reply

  • Replied 10 September 2017, 11:29 am EST

    Hi,
     
    it is a common issue which is not related to
    C1WebGrid. If you replace C1WebGrid with MS DataGrid or GridView controls you
    would see the same.
     
    There is a couple of solutions:
     
    1) Try to bind grid to data not at each page load
    in the Page_Load
    event handler, but as shown below
     
    Protected Sub Page_Load(...)
     
      If (Not
    Page.IsPostBack)
        .. bind grid to data here
      End
    If
     
    End Sub
     
    2) Or turn off EnableEventValidation.
     
    Regards,
    Sergey.
    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
    wrote: href="news:228101@10.0.1.98">news:228101@10.0.1.98...

     I wonder what is the reply




    href="http://helpcentral.componentone.com/cs/forums/p/81987/228101.aspx#228101">http://helpcentral.componentone.com/cs/forums/p/81987/228101.aspx#228101

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels