Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I’m working on an ASP.NET program with the code behind in C# and connected to a SQL Server database.  I want to create a timeout that sends them to the logout page after a certain number of minutes.  I’m not using session timeout because the timeout value will vary based on the user’s role.  The .aspx page has an UpdatePanel with a DetailsView that has a BoundField for the TimeOut in epoch seconds and another BoundField for the CurrentEpochSecond.  These fields are from the database using a select statement.  A second DetailsView contains a TemplateField that shows the TimeLeft using a SqlDataSource statement that selects the TimeOut minus the CurrentEpochSecond as TimeLeft. This is triggered by an AJAX timer every 60 seconds and the TimeLeft value is shown in the DetailsView.


What I have tried:

In the C# code I’ve tried several statements.  When I put 
    if (TimeLeft < 1)
      {
        Response.Redirect("~/Logout.aspx");
      }

VS shows an error that says: "The name 'TimeLeft' does not exist in the current context"

When I define TimeLeft as an int and change it to

    int TimeLeft;
    if (TimeLeft < 1)
      {
        Response.Redirect("~/Logout.aspx");
      }

VS shows an error that says: "Use of unassigned local variable 'TimeLeft'".
Posted
Updated 1-Jul-19 0:57am
v2

1 solution

TimeLeft has to be a updateable value, you can't just assign it a value and expect it to work. Like wise you have to update the value using a timer such as; jquery timer, asp timer, etc..

See this [^] answer for more details.
 
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