Sir good evening
Sir, i am facing a problem page refreshing problem with session continue option. if I click continue YES.
how to prevent page refresh on click continue yes button on session expiring message in asp.net
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AtestSessionTimeOut.aspx.cs" Inherits="AtestSessionTimeOut" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<%-- =========== Start For Session Time Out ======================================== --%>
<script type="text/javascript">
function SessionExpireAlert(timeout) {
var seconds = timeout / 1000;
document.getElementsByName("secondsIdle").innerHTML = seconds;
document.getElementsByName("seconds").innerHTML = seconds;
setInterval(function () {
seconds--;
document.getElementById("seconds").innerHTML = seconds;
document.getElementById("secondsIdle").innerHTML = seconds;
}, 1000);
setTimeout(function () {
//Show Popup before 20 seconds of timeout.
$find("mpeSessionTimeout").show();
}, timeout - 20 * 1000);
setTimeout(function () {
window.location = "LoginPage.aspx";
}, timeout);
};
function ResetSession() {
//Redirect to refresh Session.
window.location = window.location.href;
}
</script>
<%-- End =========== Start For Session Time Out ======================================== --%>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<%--https://getbootstrap.com/docs/5.1/components/modal/--%>
<%--https://www.w3schools.com/colors/colors_groups.asp--%>
<%--https://developer.mozilla.org/en-US/docs/Web/CSS/background-color--%>
<%-- =========== Start For Session Time Out ======================================== --%>
<div class="container">
<h3>Session Idle: <span id="secondsIdle"></span> seconds.</h3>
<asp:LinkButton ID="lnkFakeSessionTimeOut" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="mpeSessionTimeout" BehaviorID="mpeSessionTimeout" runat="server" PopupControlID="pnlPopupSessionTimeout" TargetControlID="lnkFakeSessionTimeOut"
OkControlID="btnSessionYes" CancelControlID="btnSessionNo" BackgroundCssClass="modalBackground" OnOkScript="ResetSession()">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pnlPopupSessionTimeout" CssClass=" bg-info" runat="server">
<div class="modal-header fs-5">
<asp:Label ID="Label7" runat="server" CssClass="fs-4 text-center" Text="Session Expiring!"></asp:Label>
</div>
<div class="modal-body">
Your Session will expire in <span id="seconds"></span> seconds.<br />
Do you want to continue session ?
</div>
<div class=" modal-footer" align="right">
<div class="container-fluid ">
<div class="container mb-1 p-0 ">
<div class="float-lg-start float-none">
<asp:Button ID="btnSessionYes" runat="server" Text="Yes" CssClass=" btn btn-success " />
</div>
<div class="float-lg-end fs-5 " style="color: blue">
<asp:Button ID="btnSessionNo" runat="server" Text="No" CssClass=" btn btn-danger" />
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</asp:Panel>
</div>
<%-- =========== Start For Session Time Out ======================================== --%>
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
<asp:ListItem>ONE</asp:ListItem>
<asp:ListItem>TWO</asp:ListItem>
<asp:ListItem>THREE</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Configuration;
public partial class AtestSessionTimeOut : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// =========== Start For Session Time Out ========================================
Response.Cache.SetCacheability(HttpCacheability.NoCache);
// =========== Start For Session Time Out ========================================
if (!this.IsPostBack)
{
// =========== Start For Session Time Out ========================================
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;
ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
// =========== Start For Session Time Out ========================================
}
}
///
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SessionTimeOut();
//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;
//ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
}
protected void Button1_Click(object sender, EventArgs e)
{
SessionTimeOut();
}
protected void SessionTimeOut()
{
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;
ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
}
// End Session time out
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
}
}