Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai All,
I am using ajaxtoolkit’s modalpopupextender control to alert user about expiring session.what i need for every 5mins if the site is ideal it will show alert message your seesion is expering if u want to extend if it is ok then u have reset the time like that for that
i wrote my code like this.but dnt knw i am getting error in script its not wroking properly can any one tel me how to do this task
JavaScript
<script type="text/javascript">
            function ShowAlert() {
                $find('mpe_alert').show();
            }
            function hide() {
                $find('mpe_alert').hide();
            }
            function onOk() {
                $find('mpe_alert').hide();
                _doPostBack($find('btnOk'), '')
            }


in body tag i worote like this
ASP.NET
body>
    <form id="form1" runat="server">
        <%--  <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="180" ScriptMode="Release" EnableScriptGlobalization="true" EnablePageMethods="true" >
    </asp:ScriptManager>--%>
        <telerik:RadScriptManager  runat="server" ID="RadScriptManager1" EnablePageMethods="true" />
        <telerik:RadSkinManager ID="QsfSkinManager"  runat="server" Skin="Metro" ShowChooser="false" />
   <asp:HiddenField ID="hdnSessionExpire" runat="server" />
            <cc1:ModalPopupExtender ID="mpe_alert"  runat="server" TargetControlID="hdnSessionExpire"
                PopupControlID="pnlAlert" CancelControlID="btnCancel" OkControlID="btnOk" BehaviorID="mpe_alert"  önOkScript="onOk()">
            </cc1:ModalPopupExtender>
            <asp:Panel ID="pnlAlert" runat="server" Height="100px"
                Style="display: none" Width="250px">
                <table width="100%">
                    <tr>
                        <td align="left" style="font-weight: bold; font-family: Arial">
                            <asp:Label ID="lblSessionAlert" runat="server" Text="Session Expiry Alert"></asp:Label>
                    </tr>
                </table>
                <table>
                    <tr>
                        <td colspan="2">
                            <asp:Label ID="lblMessage" runat="server" Font-Bold="true" Text="Your session is going to expire in 1 minute. Would you like to extend your session?"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Button Text="Yes" value="Yes" runat="server" ID="btnOk" />
                        </td>
                        <td align="left">
                            <asp:Button Text="Cancel" value="No" runat="server" ID="btnCancel" />
                        </td>
                    </tr>
                </table>
            </asp:Panel>

        </div>

and this is my .cs file code
C#
Session.Timeout = 5;
           int MillisecondsTimeout = (Session.Timeout * 60000) - 120000;
           string strScriptAlert = @"window.setInterval('ShowAlert()' , " + MillisecondsTimeout.ToString() + @");   ";
           ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", strScriptAlert, true);

           int Timeout = (Session.Timeout * 60000) - 60000;
           string strScriptHideAlert = @"window.setInterval('hide()' , " + Timeout.ToString() + @");   ";
           ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "HideAlert", strScriptHideAlert, true);
           Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60)) + ";URL=Login.aspx");
Posted

see this article may be it help you
Session Time Out Warning Message Using jQuery in ASP.NET[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900