我有一个 gridView 来显示文档 (.PDF) 列表和一个 LinkButton 来下载/阅读文档。
链接按钮:
<ItemTemplate>
<asp:LinkButton ID="lbDocTitle" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID") %>' Text='<%# DataBinder.Eval(Container.DataItem, "Content") %>' OnClick="lbDocTitle_Click"></asp:LinkButton>
</ItemTemplate>
lbDocTitle_click
protected void lbDocTitle_Click(object sender, EventArgs e)
{
LinkButton btn = (sender as LinkButton);
int docID = Convert.ToInt32(btn.CommandArgument);
//get fileName from docID here...
ReadPdfFile(fileName);
}
private void ReadPdfFile(string fName)
{
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(fName);
if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}
上面的所有代码都完美无缺。
接下来我做了一些改进:在服务器上执行代码时添加一个加载屏幕
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:GridView ...> <!-- move gridview here -->
</ContentTemplate>
</UpdatePanel>
<asp:UpdatePanelAnimationExtender ID="upae" BehaviorID="animation" runat="server" TargetControlID="updatePanel">
<Animations>
<OnUpdating>
<Parallel duration="0">
<ScriptAction Script="onUpdating();" />
</Parallel>
</OnUpdating>
<OnUpdated>
<Parallel duration="0">
<ScriptAction Script="onUpdated();" />
</Parallel>
</OnUpdated>
</Animations>
</asp:UpdatePanelAnimationExtender>
脚本:
function onUpdating() {
$('#loadingBox-holder').show();
$('#loadingBox').show();
}
function onUpdated(x) {
$('#loadingBox-holder').hide();
$('#loadingBox').hide();
}
改进后,当点击lblDocTitle
LinkButton 时,加载屏幕会显示并且仍在加载 loading loading... 并且永远加载。
我不知道为什么以及如何修复该错误希望有所帮助?
谢谢 !