I have the following jquery that registers a timer interval to occur every 10 seconds on the webpage whenever an input button called btnExport is clicked.
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
});
}
});
}
However, under certain scenarios I need the timer interval to begin ticking just as soon as the page load itself is loaded. My problem is that I am not sure how to do this from within the page load event of the codebehind. In theory it would go something like...
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);
}
}
}
}
I tried to accomplish this by registering a startup script, but it doesn't like the script because it doesn't know what ExportProgressCheck is...
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(cstype, csname1,
"<script type=\"text/javascript\">window.setInterval(ExportProgressCheck, 10000);</script>",
false);
Any help on this would be very appreciated! Thanks!
Pulled this off by going another route. I use jQuery's $get function to hit another aspx page to get the condition value.
ExportInProgCheck.aspx simply returns 'true' if the condition is met, at which point the window.setInterval gets set.