Reputation: 2074
Doing some javascript for the first time. I'm playing around with a sessiontimeout and it was working well while I had the code within the .aspx page. Next stape was to put the code in a .js page. So here's my current lineup.
Script.aspx.js
var iddleTimeoutWarning = null;
var iddleTimeout = null;
function pageLoad()
{
if (iddleTimeoutWarning != null)
clearTimeout(iddleTimeoutWarning);
if (iddleTimeout != null)
clearTimeout(iddleTimeout);
var millisecTimeOutWarning = <%= int.Parse(System.Configuration.ConfigurationManager.AppSettings["SessionTimeoutWarning"]) * 60 * 1000 %>;
var millisecTimeOut = <%= int.Parse(System.Configuration.ConfigurationManager.AppSettings["SessionTimeout"]) * 60 * 1000 %>;
iddleTimeoutWarning = setTimeout("DisplayIddleWarning()", millisecTimeOutWarning);
iddleTimeout = setTimeout("TimeoutPage()", millisecTimeOut);
}
function DisplayIddleWarning()
{
document.getElementById("LblWarning").innerHTML = "Warning Message";
}
function TimeoutPage()
{
__doPostBack('FiresAutoIdle','');
}
ASPX page (Pretty sure error is here since the code in .js page works)
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="Scripts/Script.aspx.js"/>
</Scripts>
</asp:ScriptManager>
I also have some code lines in web.config to set keys SessionTimeout and SessionTimeoutWarning.
So, any idea on where's the glitch? Things used to run, now they won't.
EDIT
So, asp.nex page is not loading pageLoad() function from .js.
Upvotes: 0
Views: 298
Reputation: 2074
Solved.
You can't set asp variables inside of javascript. So we have to set the variables in ASPX page, and then let javascript use them.
ASPX
<script type="text/javascript">
var millisecTimeOutWarning = <%= int.Parse(System.Configuration.ConfigurationManager.AppSettings["SessionTimeoutWarning"]) * 60 * 1000 %>;
var millisecTimeOut = <%= int.Parse(System.Configuration.ConfigurationManager.AppSettings["SessionTimeout"]) * 60 * 1000 %>;
</script>
Then use them in .js file.
Upvotes: 1