Hi arvindasp,
If you dont want to refresh the page on Continue button click then you need to use AJAX to call WebMethod from server side instead of using window.location.
I am using this article and modified the code as per your requirement.
First, you need to set the EnablePageMethods to TRUE inside the ScriptManager.
Please refer the below code.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<h3>Session Idle: <span id="secondsIdle"></span> seconds.</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> seconds.<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>
jQuery AJAX
<script type="text/javascript">
var interval = null;
var timeOutPopup = null;
var timeOutRedirect = null;
function SessionExpireAlert(timeout) {
var seconds = timeout / 1000;
document.getElementsByName("secondsIdle").innerHTML = seconds;
document.getElementsByName("seconds").innerHTML = seconds;
interval = setInterval(function () {
seconds--;
document.getElementById("seconds").innerHTML = seconds;
document.getElementById("secondsIdle").innerHTML = seconds;
}, 1000);
timeOutPopup = setTimeout(function () {
//Show Popup before 20 seconds of timeout.
$find("mpeTimeout").show();
}, timeout - 20 * 1000);
timeOutRedirect = setTimeout(function () {
window.location = "Expired.aspx";
}, timeout);
};
function ResetSession() {
//Redirect to refresh Session.
//window.location = window.location.href;
PageMethods.ResetSession(OnSuccess);
function OnSuccess(response, userContext, methodName) {
if (interval != null) {
clearInterval(interval);
}
if (timeOutPopup != null) {
clearTimeout(timeOutPopup);
}
if (timeOutRedirect != null) {
clearTimeout(timeOutRedirect);
}
SessionExpireAlert(response);
}
};
</script>
Namespace
C#
using System.Web.Services;
using System.Configuration;
using System.Web.Configuration;
VB.Net
Imports System.Web.Services
Imports System.Configuration
Imports System.Web.Configuration
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
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 * 30;
ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
}
}
[WebMethod]
public static int ResetSession()
{
HttpContext.Current.Session["Reset"] = true;
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
int timeout = (int)section.Timeout.TotalMinutes * 1000 * 30;
return timeout;
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Not Me.IsPostBack Then
Session("Reset") = True
Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~/Web.Config")
Dim section As SessionStateSection = CType(config.GetSection("system.web/sessionState"), SessionStateSection)
Dim timeout As Integer = CInt(section.Timeout.TotalMinutes) * 1000 * 30
ClientScript.RegisterStartupScript(Me.[GetType](), "SessionAlert", "SessionExpireAlert(" & timeout & ");", True)
End If
End Sub
<WebMethod>
Public Shared Function ResetSession() As Integer
HttpContext.Current.Session("Reset") = True
Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~/Web.Config")
Dim section As SessionStateSection = CType(config.GetSection("system.web/sessionState"), SessionStateSection)
Dim timeout As Integer = CInt(section.Timeout.TotalMinutes) * 1000 * 30
Return timeout
End Function
Screenshot