문제

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.

도움이 되었습니까?

해결책

In your page load check of IsPostBack

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        //your code here
    }
}

다른 팁

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top