jithesh
jithesh

Reputation: 253

Issue while clicking on ImageButton

In grid there is an image button to download file .While clicking this image button i am getting error.

 <asp:GridView ID="GridImport" runat="server" AutoGenerateColumns="false" Width="99%" Height="50%"
                                       AllowPaging="true" GridLines="None" Style="padding: 15px; text-align: left; overflow: scroll;
                                       font-family: Arial; font-size: 11pt;" ShowHeaderWhenEmpty="true" PageSize="5"
                                       CssClass="Grid_LE" HeaderStyle-CssClass="Grid_Head" EmptyDataText = "No files Imported">
                   <Columns>
                       <asp:BoundField DataField="Text" HeaderText="File Name" />
                       <asp:TemplateField>
                           <ItemTemplate>
                            <%--   <asp:LinkButton ID="lnkDownload" Text = "Download" CommandArgument = '<%# Eval("Value") %>' runat="server" OnClick = "DownloadFile" ></asp:LinkButton> --%>
                                 <asp:ImageButton ID="lnkDownload" runat="server" CommandArgument='<%# Eval("Value") %>'  Style="width: 24px; height: 24px;" ImageUrl="~/Images/download.png" OnClick="DownloadFile" />   <%--CommandName="Upload"--%>
                           </ItemTemplate>
                       </asp:TemplateField>
                       <asp:TemplateField>
                           <ItemTemplate>
                               <%--<asp:LinkButton ID = "lnkDelete" Text = "Delete" CommandArgument = '<%# Eval("Value") %>' runat = "server" OnClick = "DeleteFile" /> --%>
                                 <asp:ImageButton ID="lnkDelete" runat="server" CommandArgument='<%# Eval("Value") %>'  Style="width: 24px; height: 24px;" ImageUrl="~/Images/cancel.png" OnClick="DeleteFile" />
                           </ItemTemplate>
                       </asp:TemplateField>
                   </Columns>
               </asp:GridView>

HERE is my DownloadFile function

protected void DownloadFile(object sender, EventArgs e)
       {
           string filePath = (sender as ImageButton).CommandArgument;
           Response.ContentType = ContentType;
           Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
           Response.WriteFile(filePath);
           Response.End();
       }

WHILE CLICKING ON DOWNLOAD BUTTON I AM GETTING THIS ERROR

Server Error in '/' Application.

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.

HOW CAN I SOLVE THIS?

Upvotes: 0

Views: 616

Answers (2)

jithesh
jithesh

Reputation: 253

Invalid postback or callback argument. Event validation is enabled using 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.

Here is the solution :

<%@ Page Title="" Language="C#" 
EnableEventValidation="false" %>

Upvotes: 1

Manoj
Manoj

Reputation: 631

bind your gridview in Page_Load()

if (!IsPostBack)
{
    //Your code for Bind data 
}

for more information go to: Error: Invalid postback or callback argument

Upvotes: 1

Related Questions