session timeout causes postback?

2 posts, 0 answers
  1. K
    K avatar
    3 posts
    Member since:
    Jun 2011

    Posted 05 Oct 2011 Link to this post

    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" "">
        <head runat="server">
            <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) {
                        this[timer] = null;
                    //reset timers for UI
                    function resetTimer(timer, func, interval) {
                        this[timer] = setInterval(Function.createDelegate(this, func), interval);
                    function OnClientShowing(sender, args) {
                        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) {
                            //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() {
                        var notification = $find("RadNotificationSessionTimeout");
                        toRedirect = false;
            <form id="form1" runat="server">
                <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                    <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" >
                            <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">
                                <asp:Button ID="continueSession" runat="server" Text="Continue Your Session"
                                            Style="margin-top: 10px;" AutoPostBack="false" OnClientClicked="ContinueSession">

    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)
  2. Marin Bratanov
    Marin Bratanov avatar
    4442 posts

    Posted 06 Oct 2011 Link to this post


    Let me start by stating the the ClientIDMode property's Static value is not supported by the RadControls for ASP.NET AJAX. They are mostly complex HTML structures and many of them have content templates which are INaming containers. Therefore the ClientIDMode should be left to Auto in order for them to function correctly. This approach is advised by Microsoft as well for INaming containers.

    I also advise that you take the exact code from the demo and build on top of it, as I see some other properties set.

    Your actual issue (the full postback) stems from the way you have attached the handler to the button  - you are using a regular asp button and not a RadButton, so it has no AutoPostBack property and its client-side click event is the OnClientClick property, which requires the return false; statement to cancel the postback:
    <asp:Button ID="continueSession" runat="server" Text="Continue Your Session"
                Style="margin-top: 10px;" OnClientClick="ContinueSession(); return false;">

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top