From what I understand, the way the demo is set up, when the 'Continue Session' button is clicked, a callback should reset the session on the server, meaning the entire page should not be refreshed. And indeed I do not notice a page refresh on the demo. Yet, my page refreshes every time the session is continued. Is there a way to reset the session without this page refresh?
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RadNotificationSolution.Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
<
telerik:RadCodeBlock
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
var timeLeftCounter = null;
var seconds = 60;
//a flag to ease the logic which determines whether to redirect the user
//will not redirect if the RadButton is clicked
var toRedirect = true;
//stop timers for UI
function stopTimer(timer) {
clearInterval(this[timer]);
this[timer] = null;
};
//reset timers for UI
function resetTimer(timer, func, interval) {
this.stopTimer(timer);
this[timer] = setInterval(Function.createDelegate(this, func), interval);
};
function OnClientShowing(sender, args) {
console.log("OnClientShowing()");
resetTimer("timeLeftCounter", UpdateTimeLabel, 1000);
//raise the flag again so that a redirect will occur if the notification autocloses
toRedirect = true;
}
function OnClientHiding(sender, args) {
if (toRedirect) {
window.location.href = sender.get_value();
}
}
//update the text in the label in RadNotification
//this could also be done automatically by using UpdateInterval. However, this will cause callbacks [which is the second best solution than javascript] on every second that is being count
function UpdateTimeLabel(toReset) {
console.log("UpdateTimeLabel():", toReset);
var sessionExpired = (seconds == 0);
if (sessionExpired) {
stopTimer("timeLeftCounter");
//redirect to session expired page - simply take the url which RadNotification sent from the server to the client as value
window.location.href = $find("RadNotificationSessionTimeout").get_value();
} else {
var timeLbl = $get("timeLbl");
timeLbl.innerHTML = seconds--;
}
}
function ContinueSession() {
console.log("ContinueSession()");
var notification = $find("RadNotificationSessionTimeout");
toRedirect = false;
notification.update();
notification.hide();
}
</
script
>
</
telerik:RadCodeBlock
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
div
>
<
asp:Literal
runat
=
"server"
ID
=
"literalContent"
></
asp:Literal
>
<
telerik:RadNotification
ID
=
"RadNotificationSessionTimeout"
runat
=
"server"
ClientIDMode
=
"Static"
Position
=
"Center"
Width
=
"240"
Height
=
"200"
OnCallbackUpdate
=
"OnCallbackUpdate"
Value
=
"/Logout.aspx?timeout=true"
AutoCloseDelay
=
"60000"
Title
=
"Stay Signed In?"
Skin
=
"Office2010Blue"
EnableRoundedCorners
=
"true"
OnClientShowing
=
"OnClientShowing"
OnClientHiding
=
"OnClientHiding"
LoadContentOn
=
"PageLoad"
ShowCloseButton
=
"False"
>
<
ContentTemplate
>
<
div
class
=
"notificationContent"
>Time remaining: <
span
id
=
"timeLbl"
>60</
span
>
<%--<
telerik:RadButton
Skin
=
"Office2007"
ID
=
"continueSession"
runat
=
"server"
Text
=
"Continue Your Session"
Style
=
"margin-top: 10px;"
AutoPostBack
=
"false"
OnClientClicked
=
"ContinueSession"
>
</
telerik:RadButton
>--%>
<
asp:Button
ID
=
"continueSession"
runat
=
"server"
Text
=
"Continue Your Session"
Style
=
"margin-top: 10px;"
AutoPostBack
=
"false"
OnClientClicked
=
"ContinueSession"
>
</
asp:Button
>
</
div
>
</
ContentTemplate
>
</
telerik:RadNotification
>
</
div
>
</
form
>
</
body
>
</
html
>
using
System;
using
Telerik.Web.UI;
namespace
RadNotificationSolution
{
public
partial
class
Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
Random random =
new
Random();
literalContent.Text = random.Next().ToString();
// Session Timeout Config
if
(!IsPostBack)
{
//set the expire timeout for the session
Session.Timeout = 2;
//configure the notification to automatically show 1 min before session expiration
RadNotificationSessionTimeout.ShowInterval = (Session.Timeout - 1) * 60000;
//set the redirect url as a value for an easier and faster extraction in on the client
RadNotificationSessionTimeout.Value = Page.ResolveClientUrl(
"Logout.aspx?timeout=true"
);
}
}
protected
void
OnCallbackUpdate(
object
sender, RadNotificationEventArgs e)
{
}
}
}