Hi doctork11,
Check this example. Now please take its reference and correct your code.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
.modalBackground
{
background-color: Black;
filter: alpha(opacity=60);
opacity: 0.6;
}
.modalPopup
{
background-color: #FFFFFF;
width: 300px;
border: 3px solid #0DA9D0;
border-radius: 12px;
padding: 0;
}
.modalPopup .header
{
background-color: #2FBDF1;
height: 30px;
color: White;
line-height: 30px;
text-align: center;
font-weight: bold;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
}
.modalPopup .body
{
padding: 10px;
min-height: 50px;
text-align: center;
font-weight: bold;
}
.modalPopup .footer
{
padding: 6px;
}
.modalPopup .yes, .modalPopup .no
{
height: 23px;
color: White;
line-height: 23px;
text-align: center;
font-weight: bold;
cursor: pointer;
border-radius: 4px;
}
.modalPopup .yes
{
background-color: #2FBDF1;
border: 1px solid #0DA9D0;
}
.modalPopup .no
{
background-color: #9F9F9F;
border: 1px solid #5C5C5C;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<h3>
Session Idle: <span id="secondsIdle"></span> </h3>
<asp:LinkButton ID="lnkFake" runat="server" />
<asp:ModalPopupExtender ID="mpeTimeout" BehaviorID="mpeTimeout" runat="server" PopupControlID="pnlPopup"
TargetControlID="lnkFake" OkControlID="btnYes" CancelControlID="btnNo" BackgroundCssClass="modalBackground"
OnOkScript="ResetSession()">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Session Expiring!
</div>
<div class="body">
Your Session will expire in <span id="seconds"></span><br />
Do you want to reset?
</div>
<div class="footer" align="right">
<asp:Button ID="btnYes" runat="server" Text="Yes" CssClass="yes" />
<asp:Button ID="btnNo" runat="server" Text="No" CssClass="no" />
</div>
</asp:Panel>
<script type="text/javascript">
function SessionExpireAlert(timeout) {
var totalSeconds = timeout / 1000;
var minutes = Math.floor(totalSeconds / 60);
var seconds = Math.floor(totalSeconds - minutes * 60);
document.getElementById("seconds").innerHTML = parseInt(minutes) + " minutes " + parseInt(seconds) + " seconds";
document.getElementById("secondsIdle").innerHTML = parseInt(minutes) + " minutes " + parseInt(seconds) + " seconds";
setInterval(function () {
totalSeconds--;
minutes = Math.floor(totalSeconds / 60);
seconds = Math.floor(totalSeconds - minutes * 60);
document.getElementById("seconds").innerHTML = parseInt(minutes) + " minutes " + parseInt(seconds) + " seconds";
document.getElementById("secondsIdle").innerHTML = parseInt(minutes) + " minutes " + parseInt(seconds) + " seconds";
}, 1000);
setTimeout(function () {
//Show Popup before 60 seconds i.e. 1 minute 0 seconds of timeout.
$find("mpeTimeout").show();
}, timeout - 60 * 1000);
setTimeout(function () {
window.location = "Expired.aspx";
}, timeout);
};
function ResetSession() {
//Redirect to refresh Session.
window.location = window.location.href;
}
</script>
</form>
</body>
</html>
C#
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (!this.IsPostBack)
{
Session["Reset"] = true;
System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
System.Web.Configuration.SessionStateSection section = (System.Web.Configuration.SessionStateSection)config.GetSection("system.web/sessionState");
int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Not Me.IsPostBack Then
Session("Reset") = True
Dim config As System.Configuration.Configuration = Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/Web.Config")
Dim section As Web.Configuration.SessionStateSection = DirectCast(config.GetSection("system.web/sessionState"), Web.Configuration.SessionStateSection)
Dim timeout As Integer = CInt(section.Timeout.TotalMinutes) * 1000 * 60
ClientScript.RegisterStartupScript(Me.GetType(), "SessionAlert", "SessionExpireAlert(" & timeout & ");", True)
End If
End Sub
Web.Config
<sessionState timeout="20"/>