0

I have tried an application in which user can extend his session to further 7 mins when there are only 5 mins left for session to get over by use of a button click.but my code is not working...Kindly help...Here is my code

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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">
<script type="text/javascript" language="javascript">

    var sessionTimeout = "<%= Session.Timeout %>";
    function DisplaySessionTimeout() {
        //assigning minutes left to session timeout to Label
        document.getElementById("<%= lblSessionTime.ClientID %>").innerText =
                                                                        "Your Session Time left : " +sessionTimeout +" minutes";

sessionTimeout = sessionTimeout - 1;
 document.write(sessionTimeout);

       if(sessionTimeout > 0)
       {
       //if session is not less than 0
        if (sessionTimeout >= 5)
        //call the function again after 1 minute delay
            window.setTimeout("DisplaySessionTimeout()",60000);

        if(sessionTimeout == 4)
     {
    document.write(sessionTimeout);
 window.open("SessionExtender.aspx",null,"status=no,toolbar=no,menubar=no,location=no,width=360,height=280");

          sessionTimeout ="<%= Session["Time"] %>" 
          document.write(sessionTimeout);

          }
          window.setTimeout("DisplaySessionTimeout()",60000);
    }
    }
    else
    window.location="Error.htm";



    }


    </script>

    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server" >
    <div>
    <asp:Label id="lblSessionTime" runat="server" Text="" Font-Size="X-Large" Visible="true"></asp:Label>
  <%-- <asp:Button ID="btnSubmit" runat="server" Text="submit" OnClick="btnSubmit_Click"  />--%>
    </div>

    </form>
</body>
</html>


Code Behind: using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(),
              "onLoad", "DisplaySessionTimeout()", true);

    }

}


SessionExtender.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SessionExtender.aspx.cs" Inherits="SessionExtender" %>

<!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 id="Head1" runat="server">
    <title>Session Expire</title>
    <script type="text/javascript">
    var sessionTimeout = "<%= Session.Timeout %>";
     function post_value()
            {





        <%Session["Time"] = 7;%>




                self.close();

            }


    </script>
</head>
<body>
    <form id="form1" runat="server"  >

    <div style ="padding-top : 15px; background-color: #E3E3F4; border-top-style: solid ; border-right-style: solid;border-left-style: solid;border-bottom-style: solid; border-color:Blue; font-family:Zurich BT" >
    <center>


        <table  >
            <tr>
                <td colspan="2">
                   <h3> 
                       <span style="text-decoration: underline; font-family:Zurich BT">E-Governance Solution</span>
                       </h3>                    
                </td>
            </tr>
            <tr>
                <td >
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/powerpoint-timer.GIF" Height="151px" Width="155px" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" /></td>
                <td align="center">
                    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Zurich BT" Font-Size="Large" 
                        Text="Your session will expire in 5 minutes, please click “OK” to extend your session"></asp:Label><br />
                    &nbsp;</td>
            </tr>
            <tr>
            <td></td>
                <td>

        <asp:Button ID="Button1" runat="server" Text="Ok" Width="59px" OnClientClick = "post_value()" /></td>
            </tr>
        </table>


    </center>


    </div>
    </form>
</body>
</html>
2
Contributors
1
Reply
14
Views
4 Years
Discussion Span
Last Post by LastMitch
0

I have tried an application in which user can extend his session to further 7 mins when there are only 5 mins left for session to get over by use of a button click.but my code is not working...Kindly help...Here is my code

@amrita111

I'll be honest with you. I feel the issue you are havin is more javascript than ASP.net. I'm not very familiar with implementing javascript on C#.

I assume you test out the javascript code to see how it works before you implementing the code?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.