learned/learning/to learn RSS 2.0
# Wednesday, 30 September 2009

This article describes how to notify users about session expiration and allow them to renew the session.

Controls that need to be added:
1. A Panel with an OK button.

2. A label with session expiration notification message.

3. An AJAX ModalPopupExtender.

4. A dummy button and set ModalPopupExtender’s TargetControlId as this button.

 

This is how it looks:

 

<cc1:ModalPopupExtender ID="modext_promptmessage" runat="server" BehaviorID="popup_promptmessage"

    PopupControlID="pnl_popup" TargetControlID="btn_dummy">

</cc1:ModalPopupExtender>

<asp:Panel ID="pnl_popup" runat="server" Style="display: none">

    <table cellpadding="0" cellspacing="0" border="0">

        <tr valign="top">

            <th>

                Prompt Message

            </th>

        </tr>

        <tr>

            <td>               

                        <label>Your session is going to expire in 2 minutes. Please click OK to renew it."></label>

<asp:Button ID="btn_ok" runat="server" OnClientClick="ResetSession()" Text="OK" />

            </td>

        </tr>

    </table>

</asp:Panel>

 

My code behind class looks like this:

 

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

     

      ' checks whether session expired

      If Current.Session.Keys.Count = 0 Then

                        Response.Redirect("sessionexpired.aspx", True)

            Exit Sub

      End If

 

' Javascript function PromptSessionExpiration() will be called 2 minutes before session expiration (120000 milliseconds)

      Dim strExpireSessionScript As String = String.Format("setTimeout('PromptSessionExpiration()', {0}); ", (Me.Session.Timeout * 60000) - 120000)

      Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "expirescript", strExpireSessionScript, True)

 

   End Sub

 

   ''' This click event will renew the session, need not add any code inside it

   Protected Sub btn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ok.Click 

   End Sub

 

 

My javascript:

 

<script language="javascript" type="text/javascript">

 

    function PromptSessionExpiration() {

              // the function below will be triggered at the 125th second

        setTimeout('CheckSessionStatus()', 125000);

        // show popup

        $find('popup_promptmessage').show();

    }

 

    // handles closing popup

    function ResetSession() {

        $find('popup_promptmessage').hide();

    }

 

    // this function will be called if user doesn’t respond to the prompt message

    // which will redirect to sessionexpired page

    function CheckSessionStatus() {

            window.location = “sessionexpired.aspx”;

    }   

  

 </script>

 

Thanks.

Wednesday, 30 September 2009 19:55:52 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
.NET
Navigation
Archive
<2009 September>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Gokulnath
Sign In
Statistics
Total Posts: 41
This Year: 0
This Month: 0
This Week: 0
Comments: 47
Themes
Pick a theme:
All Content © 2017, Gokulnath
DasBlog theme 'Business' created by Christoph De Baene (delarou)