Link to home
Start Free TrialLog in
Avatar of ToolTimeGang
ToolTimeGangFlag for United States of America

asked on

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

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:

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

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:
http://msdn.microsoft.com/en-us/library/system.web.configuration.pagessection.enableeventvalidation(VS.90).aspx)

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

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!
ASKER CERTIFIED SOLUTION
Avatar of Designbyonyx
Designbyonyx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ToolTimeGang

ASKER

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 line...so I used this:
<asp:LinkButton ID="LinkButtonEdit" runat="server" CausesValidation="false" CommandName="Edit">
               <asp:Image ID="imgFolder" runat="server" ImageUrl="~/images/edit.gif" />
</asp:LinkButton>

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!
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?
Nope...I'm good!  Thanks again!