if (!this.IsPostBack)
{
Session["Reset"] = true;
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
Page.ClientScript. RegisterStartupScript(this.GetType(), "onLoad", "DisplaySessionTimeout(" + timeout + ")", true);
}
<script type="text/javascript">
var sessionTimeout = "<%= Session.Timeout %>";
function DisplaySessionTimeout(timeout) {
var seconds = timeout / 1000;
document.getElementsByName("seconds").innerHTML = seconds;
setInterval(function () {
seconds--;
document.getElementById("seconds").innerHTML = seconds;
}, 1000);
setTimeout(function () {
//Show Popup before 20 seconds of timeout.
$("#ExpireConfirm_Submit").dialog({
height: 200,
width: 400,
resizable: false,
modal: true,
title: "Session Expire Confirmation",
open: function () {
$('p#id1').html(sessionTimeout);
},
buttons: {
"Yes": function () {
$(location).attr("href", "/Account/Logout").submit();
$(this).dialog("close");
},
"No": function () {
ResetSession();
$(this).dialog("close");
}
}
}).prev(".ui-dialog-titlebar").css("background", "red");
}, timeout - 20* 1000);
setTimeout(function () {
$(location).attr("href", "/Account/Logout").submit();
}, timeout);
};
function ResetSession() {
window.location = window.location.href;
}
</script>
if user in other tab. how can we set focus to dialog box.