Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi professsionals

there is conditon in my project where i need to do login by client and after login i have to give him only one hour time for accessbility of my site strat time will be login time and it will store in Database i need to do only that take login time from DB and show counter with that time and after one hour need to do only Response.Redirect("MyPage.aspx").

the main thing that i have to do this by Java script and i am new in JS try many codes but not getting actually result........can any onje help me
Posted
Comments
Khandwawala Hatim 10-Sep-13 2:21am    
is there any specific reason that you need to fetch the login time from the database only.
Shubh Agrahari 10-Sep-13 3:00am    
no its only part to convey u all people even there is many method to get store login time (session. hidden fields etc)

1 solution

Check the below code.

C#
//After you login, put the time (i.e. in minutes from database) in to a hidden feild from server side.

var sessionTimeout = "2";   // Put the value of that hidden feild in to this variable
var globalmins = 1; // Substract one minutes from the hidden feild and put it in to this variable
var timeOnPageLoad = new Date();

var redirectToWelcomePageTimer = null;

//To redirect to the welcome page
var redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()', parseInt(sessionTimeout, 10) * 60 * 1000);

var milisec = 0
var seconds = 60
var minutes = globalmins;


function display() {
    if (minutes + ":" + seconds == "0.1") {
    }
    else {
        if (milisec <= 0) {
            milisec = 10
            seconds -= 1
        }
        if (seconds <= 0) {
            milisec = 0
            seconds = 60
            minutes -= 1
        }
        if (minutes <= -1) {
            milisec = 0
            seconds = 0
        }
        else
            milisec -= 1
    }
    var timestring = "Your session will expire in " + minutes + ":" + seconds + " Minutes"
    $('#showtimeleft').html(timestring);
    setTimeout("display();", 100)
}
display();

//Session timeout
function RedirectToWelcomePage() {
    window.alert("Session expired. You will be redirected to some page");
    window.location = "Default.aspx";
}
 
Share this answer
 
Comments
Shubh Agrahari 10-Sep-13 3:25am    
it reload timer every time when page reload or refresh..
Khandwawala Hatim 10-Sep-13 3:48am    
ok just comment the call of function display(); and call it from the server side once you login
Shubh Agrahari 10-Sep-13 3:52am    
i am getting HH:MM::SS formate so can u give me the code including hour:Minute:Timer on Counter....?

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