【发布时间】:2014-11-07 06:39:00
【问题描述】:
在网格中有一个下载文件的图像按钮。单击此图像按钮时出现错误。
<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 函数
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();
}
点击下载按钮时出现此错误
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.
我该如何解决?
【问题讨论】:
标签: asp.net