我有以下 jquery,每当单击名为 btnExport 的输入按钮时,它就会在网页上每 10 秒注册一次计时器间隔。
if ($) {
$(document).ready(function () {
$("input[id$='btnExport']").click(function ($e) {
// javascript timer function
window.setInterval(ExportProgressCheck, 10000);
});
function ExportProgressCheck() {
$.ajax({
type: "POST",
url: "DMZ_Export.aspx/GetExportProgress",
contentType: "application/json; charset=utf-8",
data: "",
dataType: "json",
success: AjaxSuccess,
error: AjaxFailed
});
}
});
}
但是,在某些情况下,我需要在页面加载本身加载后立即开始计时。我的问题是我不确定如何从代码隐藏的页面加载事件中执行此操作。理论上它会像...
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
if (IsExportInProgress()) {
// Register the timer interval now!! How do I do this??
// window.setInterval(ExportProgressCheck, 10000);
}
}
}
}
我试图通过注册一个启动脚本来实现这一点,但它不喜欢这个脚本,因为它不知道 ExportProgressCheck 是什么......
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(cstype, csname1,
"<script type=\"text/javascript\">window.setInterval(ExportProgressCheck, 10000);</script>",
false);
对此的任何帮助将不胜感激!谢谢!