Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Postback argument - normal workround isnt working

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
Hi, Im getting the error;
Code:
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.

Using aps.net 3.5 I have a number of image buttons in my datagrid (template columns).

After some intense googling, it seems that the common fix for this is to not rely on the framework and explicitly register the events. So I have adjusted my Render Method as per below;

Code:
 foreach (DataGridItem item in dgManagePages.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    ImageButton ib = item.Cells[0].FindControl("expandLevel") as ImageButton;
                    Page.ClientScript.RegisterForEventValidation(ib.UniqueID, String.Format("Command${0}", item.ItemIndex));
                }
            }

However, I still get the same error when I trigger the command. I can work round this in the dev environment by turning off event validation at the page level, but this is not acceptible on the production server. Can anyone suggest further things to try ro resolve this?

Thanks

K
 
I think the problem is that you are trying to register a sever event from the client. Pretty sure you cannot do that. you must wire the event handler in the code behind.

If I read the RegisterForEventValidation correctly you are trying to register a Command handler for the row. If this is correct you can wire the event like this
Code:
<asp:gridview ... OnGridViewRowCommand="do_something">
  <columns>
     <TemplateColumn ...>
         <ItemTemplate>
            <asp:button ... CommandName="foo" CommandArg="whatever you want" />
         </ItemTemplate>
     </TemplateColumn>
  </columns>
</asp:gridview>
Code:
public void do_something(object sender, GridViewRowCommandArgs e)
{
   switch(e.CommandName)
   {
       case "foo":
          //do something with the command argument
          break;
       default:
          throw new InvalidOperationException("I don't know what to do with " + e.CommandName);
   }
}
it's something like that anyway.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
You understood me correctly, but that is exactly what I have.

Upon further investgation, Any Image Button within any Web User Control is causing this behaviour.

I suspect that the next thing I need to do is to move the code from the U/C to the page, and see if the issue remains, in which case its something to do with the fact it is in a UC, or if this is a more general issue.
 
I belive I have run into this issue before and it has something to do with the image button. Try just using a regular button and see if you get the same error.
 
Im still investigating. It appears that this is one of those errors that has multiple causs.

I have fixed one of my controls, it was binding on postbacks, hence as soon as you clicked on the image the button was having its event, id etc renewed.

Thats not the issue with the rest so I'll try the link button. The fact that the one now works means it isnt an issue directly with User Controls, so I can relax a little :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top