[RESOLVED] ImageButton OnClick cause - Invalid postback or callback argument

I have a page that uses a master page. The following code only shows the bare minimum of the page:


<asp:ListView ID="lvGalleries" runat="server">
  <LayoutTemplate>
    <table>
      <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
    </table>
  </LayoutTemplate>
  <ItemTemplate>
    <tr>
      <td>
        <asp:ImageButton OnClick="LoadGallery_Click" runat="server" ImageUrl='<%# Eval("Url") %>'  />
      </td>
    </tr>
  </ItemTemplate>
  <EmptyDataTemplate>
    <tr><td>none</td></tr>
  </EmptyDataTemplate>
</asp:ListView>




Code-behind:

protected void LoadGallery_Click(object sender, ImageClickEventArgs e) 
    {         
       //code
    }


The

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.




My guess is that it may releated to the ID's that are recreated..

Change the enableEventValidation="true" in the page directive at the top of your aspx page to 'false'

 

You have to add ListView.Databind() in the Page_Load . That will take care of the expression in the imageUrl. Hope this helps

I have DataBind() in the Page_Load.

The change of enableEventValidation="true" to false works.
But the event isnt fires / I dont get to the breakpoint at the beginning of the function. 

And what does enableEventValidation="false" cause?

can you share the code with which you are binding the listview control

Did you saw my previous reply edit?

Its nested code, that execute a select steatment and return datatable. That datatable I bind to the datasource of the listview, then I do databind...

Any thoughts?

are you doing Databinding in IsPostBack Check???? that might be one of the reason for making the event validation corrupted....do databind in all page_load...try like that....

Thanks.

protected void LoadGallery_Click(object sender, ImageClickEventArgs e)
    {
      //code
 }


    protected void Page_Load(object sender, EventArgs e)
    {
        RefreshGalleries();
    }




    private void RefreshGalleries()
    {
        lvGalleries.DataSource = // call to a function that returns datatable
        lvGalleries.DataBind();
    }

this is the code i use

Can you include the code RefreshGalleries(); in If(!IsPostBack) and check what is happening....

I seriously doubt that binding everytime the listview in page_load might cause the problem....

Thanks.

Well, nothing happens. The LoadGallery_Click still isnt firing...

When you click on the link, Does it postback to the server or open the link without a postback?

<div style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;" mce_style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;">

I see the page reload - its meen there been a postback, I put breakpoint on the LoadGalleries_Click and it didnt get there.

The ImageButton doesnt have navigateUrl as you can see so theres no link to open.

</div>

I developed a simple example w/ ListView & imageButton ,

just very similar , what you have. This works perfect & I don't see any error.

Here it is

//aspx
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ListView ID="lvGalleries" runat="server">
  <LayoutTemplate>
    <table>
      <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
    </table>
  </LayoutTemplate>
  <ItemTemplate>
    <tr>
      <td>
        <asp:ImageButton ID="ImageButton1" OnClick="LoadGallery_Click" runat="server" ImageUrl='<%# Eval("URL") %>'  />
      </td>
    </tr>
  </ItemTemplate>
  <EmptyDataTemplate>
    <tr><td>none</td></tr>
  </EmptyDataTemplate>
</asp:ListView>
</asp:Content>




//codebehind
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lvGalleries.DataSource = GetDT();
            lvGalleries.DataBind();
        }
    }


    private DataTable GetDT()
    {
        DataTable dtDFS = new DataTable();
        dtDFS.Columns.Add("ID");
        dtDFS.Columns.Add("URL");
        dtDFS.Columns.Add("Name");


        DataRow dr = dtDFS.NewRow();
        dr["ID"] = 1;
        dr["URL"] = "www.google.com";
        dr["Name"] = "Google";
        dtDFS.Rows.Add(dr);




        dr = dtDFS.NewRow();
        dr["ID"] = 2;
        dr["URL"] = "www.microsoft.com";
        dr["Name"] = "MS";
        dtDFS.Rows.Add(dr);


        dr = dtDFS.NewRow();
        dr["ID"] = 3;
        dr["URL"] = "www.yahoo.com";
        dr["Name"] = "yahoo";
        dtDFS.Rows.Add(dr);
        return dtDFS;
    }
    protected void LoadGallery_Click(object sender, ImageClickEventArgs e)
    {
        int r1 = 9;
    }


 

You got me wonder how this possible, so I dug into my code and saw that all this time i was click the wrong link (this page isnt design yet).

Thanks a lot and sorry for the HUGE mix up.

thoughts on "[RESOLVED] ImageButton OnClick cause - Invalid postback or callback argument"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>