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!
ToolTimeGangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DesignbyonyxCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ToolTimeGangAuthor Commented:
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!
0
DesignbyonyxCommented:
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?
0
ToolTimeGangAuthor Commented:
Nope...I'm good!  Thanks again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.