本文介绍了单击ImageButton时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

<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>







这是我的DownloadFile功能

----------------------------- ---------






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?

推荐答案

if (!Page.IsPostBack)
{
   //bind data to  GridImport
}





希望这会有所帮助,同样的错误可能有很多其他原因,这是我先指出的常见错误。



hope this helps, there may be many other reasons for the same error, this is the common mistake I have pointed first.


<%@ Page Title="" Language="C#" 

EnableEventValidation="false" %>



更改EnableEventValidation = false在页面


change EnableEventValidation="false" in page


<asp:GridView ID="GridImport" runat="server" onrowcommand="GridView1_RowCommand" > 





您的图片按钮为





Your Image Button as

<asp:ImageButton ID="lnkDownload" runat="server" CommandArgument='<%# Eval("Value") %>'  Style="width: 24px; height: 24px;" ImageUrl="~/Images/download.png" CommandName="DownloadFile" />







然后行命令事件






then Row Command Event

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







谢谢



Siva Rm K




Thanks

Siva Rm K


这篇关于单击ImageButton时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:59