我有一个asp.net c#网站,我在执行jscript时遇到问题。 我有一个加载包含javascript和代码的母版页。代码摘录如下。当它运行时,计时器永远不会出现。如果我单击关闭页面按钮,则会收到错误消息:
Microsoft JScript运行时错误:属性“closePage”的值为null或未定义,而不是Function对象。
就行:
<input type="submit" name="ctl00$CloseSection$btnClose" value="Close Page Now" onclick="closePage(); return false;" id="ctl00_CloseSection_btnClose" class="buttons" />
我尝试过很多东西,在var部分的上方和下方移动.js src行。似乎没有改变这一点。奇怪的是,几天前这种情况很好。我注意到MS在9月14日做了几次VS更新。
任何帮助都将不胜感激。
我可以做一个视图源,js行显示正常:
<script src="jscripts/StoreFrontClose.js" type="text/javascript"></script>
摘录如下:
<asp:ContentPlaceHolder ID="CloseSection" runat="server">
<script src="jscripts/PageClose.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
var timeoutMins = 0;
var timeoutSecs = 30;
alert("getting ready to start timer");
if (source == "kiosk") {
startPageCloseTimer();
}
<div style="text-align: center;">
The Page will close in: <span id="theTime" class="timeClass"></span>
<br />
<asp:Button ID="btnClose" CssClass="buttons" runat="server" OnClientClick="closePage();"
Text="Close Page Now" />
<asp:Button ID="btnKeepOpen" CssClass="buttons" runat="server" OnClientClick="resetTimer();"
Text="Keep Page Open a little Longer" />
</div>
</asp:ContentPlaceHolder>
PageClose.js有:
function startPageCloseTimer() {
alertTimerId = setTimeout("AlertUser()", timeoutMilli);
countDown();
}
function AlertUser() {
extend = false;
handleTimerId = setTimeout("HandleTimeout();", maxPopupTime);
jQuery("#messagePopup").dialog("open");
}
function HandleTimeout() {
if (!extend) {
closePage();
}
}
function KeepSessionAlive() {
extend = true;
resetTimer();
}
function resetTimer() {
clearTimeout(alertTimerId);
clearTimeout(handleTimerId);
alertTimerId = setTimeout("AlertUser()", timeoutMilli);
sec = timeoutSecs;
min = timeoutMins;
countDown();
}
function closePage() {
alert("getting ready to close page");
clearTimeout(handleTimerId);
clearTimeout(alertTimerId);
clearTimeout(countDownTimerId);
}
var sec = timeoutSecs; // set the seconds
var min = timeoutMins; // set the minutes
function countDown() {
sec--;
if (sec == -01) {
sec = 59;
min = min - 1;
} else {
min = min;
}
if (sec <= 9) { sec = "0" + sec; }
var time = "";
if (min > 0) {
time = (min <= 9 ? "0" + min : min) + " min and ";
}
time = time + sec + " sec ";
if (document.getElementById("theTime")) {
document.getElementById("theTime").innerHTML = time;
}
countDownTimerId = window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') {
sec = "00";
window.clearTimeout(countDownTimerId);
}
}
答案 0 :(得分:1)
您只是忘记了结束</script>
标记:
<script src="jscripts/PageClose.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
var timeoutMins = 0;
var timeoutSecs = 30;
alert("getting ready to start timer");
if (source == "kiosk") {
startPageCloseTimer();
} // end of script
</script> // close tag