Manually built gridview is getting Invalid postback or callback argument when ImageButton is used.

Posted on 2011-10-25
Last Modified: 2012-05-12
I have a gridview in a vb (framework 4.0) web form.
I am filling it manually in the code behind.

I am not overriding the EnableEventValidation.

when I include this in the gridview:

                        <!-- Edit Button -->
                           <asp:ImageButton  ID="imgEditDetail"  runat="server"
                               ImageUrl="~/images/edit.gif" ToolTip="Edit" CommandName="Edit" />

I get this when I click the edit button:
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.

However, when I use this, it works just fine.  (Note...the issue noted at the bottom of this is the same thing I am getting:

                        <!-- Edit Button -->
                        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit">Edit</asp:LinkButton>

I understand the importance of keeping the EnableEventValidation=True.  So I don't want to change that.

But how can I get this to work with my ImageButton?  

On the same page, I added another gridview, only this one is filled using an objectdatasource (that is hooked up to our n-tier layers).  When I throw an ImageButton on that gridview, it works just fine.  I am thinking it doesn't work with the other because something is recognizing the fact that the data is getting changed between the posts, so it might be getting sql injected?  so what is my work around please?   My ImageButton is more pretty to look at than a plain ole link button.

Also, when I do set EnableEventValidation=False, the error goes away, but then my gridview events don't seem to fire. (I have breakpoints set on my gridview events and when I click edit, I don't stop on the BP)

Thank you for helping me!
Question by:ToolTimeGang
    LVL 14

    Accepted Solution

    So you want an image to be clickable so that you can handle the CLICK event on the server side using the CommandName property.  ImageButton doesn't seem to be working, yet LinkButton is...

    So why not just try this:

    <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit"><asp:Image ID="imgEdit" ImageUrl="~/images/edit.gif" runat="server"></asp:LinkButton>

    Open in new window


    Author Comment

    Ok, so I feel really silly now.  I guess I didn't realize that I could assign an image to a LinkButton!  Go figure!
    There was a slight syntax error with your I used this:
    <asp:LinkButton ID="LinkButtonEdit" runat="server" CausesValidation="false" CommandName="Edit">
                   <asp:Image ID="imgFolder" runat="server" ImageUrl="~/images/edit.gif" />

    Issue resoloved.  Also, when I have BPs set in the GridView events, the code does fire with this.  So I'm all good now!

    Thank you onyx!
    LVL 14

    Expert Comment

    yeah, I saw that I forgot the closing tag on the image control... I assumed you could figure it out ;)

    Glad it got working... sometimes, you just gotta step back and see describe what you are trying to do, and other solutions seem to appear magically.  Do you need anything else?

    Author Comment

    Nope...I'm good!  Thanks again!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Read about why website design really matters in today's demanding market.
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now