4

I am getting the following error :

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.

I have an ImageButton in a Repeater like this:

<asp:ImageButton ID="btn_CreatePdf" ImageUrl="~/images/download.png" 
                 ToolTip="Create Transmittal for this Contact" 
                 CommandName="CreatePdf"   
                 CommandArgument='<%#Eval("contactid")%>' runat="server" />

When ever I click on this ImageButton, it causes that error.

But when I tried LinkButton instead of ImageButton, it's working fine. I tried following LinkButton :

<asp:LinkButton ID="btn_CreatePdf" Text="Download" CommandName="CreatePdf" 
                CommandArgument='<%#Eval("contactid")%>' runat="server" >    
</asp:LinkButton>

Please give me a solution, why I'm getting this error only in case of ImageButton.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

4

In your page load check of IsPostBack

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        //your code here
    }
}
radbyx
  • 9,352
  • 21
  • 84
  • 127
Habib
  • 219,104
  • 29
  • 407
  • 436
  • 1
    Now it is working fine for Image Buton too. But i want to know reason, why it was working fine for LinkButton withouy "Post Back" check. thanx. –  Jun 19 '12 at 06:45
3

Use: if(!Page.IsPostBack) (C#).

Also look at this answer and the others on the same question

Community
  • 1
  • 1
robasta
  • 4,621
  • 5
  • 35
  • 53
  • Now it is working fine for Image Buton too. But i want to know reason, why it was working fine for LinkButton withouy "Post Back" check. thanx. –  Jun 19 '12 at 06:45