We help IT Professionals succeed at work.

ASP.net Error clicking a button in a GridView column

Murray Brown
Murray Brown asked
on
Medium Priority
1,134 Views
Last Modified: 2012-08-12
Hi. When running the following cofde through a button on a GridView I am getting the error
shown below


Private Sub GridView1_RowCommand1(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Try

            If (e.CommandName = "MyButton6") Then
                ' Retrieve the row index stored in the CommandArgument property.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)

                ' Retrieve the row that contains the button
                ' from the Rows collection.
                Dim row As GridViewRow = GridView1.Rows(index)

                row.BackColor = Drawing.Color.LightCyan
                row.Cells(6).ForeColor = Drawing.Color.DarkGreen


            End If

        Catch ex As Exception
            Me.lblError1.Text = ex.Message
        End Try
    End Sub


Server Error in '/' Application.
--------------------------------------------------------------------------------

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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: 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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[ArgumentException: 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.]
   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +8778454
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +113
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +35
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks but I am looking for help with why my code be incorrect
Obadiah ChristopherDeveloper User Interface
CERTIFIED EXPERT

Commented:
Are you using an updatepanel?

Can u post the Gridview markup from the aspx page?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
There are two options

1) Turn off event validation
2) Register for event validation

http://odetocode.com/Blogs/scott/archive/2006/03/22/asp-net-event-validation-and-invalid-callback-or-postback-argument-again.aspx
Hello,

    Is the GridView handling the RowCommand trigger?

<asp:GridView ID="GridView1" runat="server" 
        onrowcommand="GridView1_RowCommand1">

Open in new window


Ryan F
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks very much