我正在使用带有 setTimeout 函数的 javascript 在按钮的 onclientclick 上显示 GIF。一旦从数据库中检索到数据,我就会尝试停止/隐藏 GIF。到目前为止还没有运气。我尝试了以下方法。任何帮助是极大的赞赏。
CSS
.modal {
position: fixed;
top: 0;
left: 0;
background-color: black;
z-index: 99;
opacity: 0.9;
filter: alpha(opacity=80);
-moz-opacity: 0.9;
min-height: 100%;
width: 100%;
}
.loading {
font-family: Arial;
font-size: 10pt;
width: 200px;
height: 100px;
display: none;
position: fixed;
opacity: 0.9;
z-index: 999;
}
Javascript
function ShowLoader() {
if (Page_ClientValidate('DownloadReport')) {
setTimeout(function() {
var modal = $('divLoader');
modal.addClass('modal');
$('body').append(modal);
var loading = $('.loading');
loading.show();
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({
top: top,
left: left
});
}, 100);
} else {
}
};
function HideLoader() {
document.getElementById('<%= divLoader.ClientID%>').style.visibility = "hidden";
};
所以点击按钮我调用showLoader,
<asp:Button ID="btnGenerateRep" CssClass="btnGenerateRep" runat="server" Text="Download Report" ValidationGroup="DownloadReport" OnClientClick="ShowLoader();" OnClick="btnGenerateRep_Click" />
我想在从数据库中检索数据时停止它
C#代码,
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
if (dt.Rows.Count > 0) {
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "HideLoader()", true);
string dateTimeStamp = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
string excelFileName = aliasName + "-" + dateTimeStamp + ".xlsx";
string worksheetsName = "Sheet";
var format = new ExcelTextFormat();
format.Delimiter = ',';
format.EOL = "\r";
using(ExcelPackage package = new ExcelPackage()) {
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(worksheetsName);
worksheet.Cells["A1"].LoadFromDataTable(dt, true);
Response.Clear();
package.SaveAs(Response.OutputStream);
Response.AddHeader("content-disposition", "attachment; filename=" + excelFileName + ";");
Response.Charset = "";
Response.ContentType = "application/vnd.xlsx";
Response.End();
}
}
我正在从 C# 代码调用 javascript,但它没有触发。或者,当 SaveAs 对话框从 package.SaveAs 出现时,我可以捕获 Save 命令,然后从那里调用 javascript?
我还尝试隐藏接收数据时 GIF 所在的 asp:Panel。仍然没有运气。我真的很感激任何帮助。非常感谢