Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1317
  • Last Modified:

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!
0
ToolTimeGang
Asked:
ToolTimeGang
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now