Click here to Skip to main content
15,919,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friendz,

I am stuck up with a peculiar problem.

My requirement is that when the user logs in the client side time should be saved and should be displayed on the screen.

So on our LMS Bangalore software's page I have written a JavaScript which captures the client side time and stores it in a hidden field. Then on the click of the log in button I am storing it in the Session["Clienttime"] and then displays it on the Create Employee page when the page opens.

Here is my JavaScript code:

XML
<script language="javascript" type="text/javascript">
    function EncryptMD5()
    {
        var Pass = document.getElementById("<%=txtPassword.ClientID%>").value;
        // Encrypte the password
        if (Pass.length > 0 )
        {
            var MD5Hash = hex_md5(Pass);
            var salt = document.getElementById("<%=SaltStr.ClientID%>").value;
            MD5Hash = hex_md5(salt+MD5Hash);
            document.getElementById("<%=HashPass.ClientID%>").value = MD5Hash;
            document.getElementById("<%=txtPassword.ClientID%>").value = MD5Hash;
        }
        DisplayDateTime()
    }
    function DisplayDateTime()
    {
        var DateTime = new Date();
        var strYear= DateTime.getYear();
        var strMonth= DateTime.getMonth() +1;
        var strDay = DateTime.getDate();
        var strHours = DateTime.getHours();
        var strMinutes = DateTime.getMinutes();
        var strSeconds = DateTime.getSeconds();
        var clientTime = strDay + "/" + strMonth + "/" + strYear + " " + strHours + ":" + strMinutes + ":" + strSeconds;
        document.getElementById("<%=hfClientTime.ClientID%>").value = clientTime;
    }
    </script>


Then I do this on log in buttons click:

Session["Clienttime"] = hfClientTime.Value.ToString();

and in my .aspx page i call javascript:

OnClientClick="EncryptMD5()"

and on my employee page I want to display the time so do this:

lblTime.Text = Session["Clienttime"].ToString();

The problem is when I log for the first time everything works fine. But then when I log out or close the page and again logs in I find the session cleared despite evertime assigning the time value on the login buttons click.

Can u tell me where I am going wrong?

Thanking You

Swapnil Borkar.
Posted
Comments
Rajesh Sajjanar 25-Sep-10 7:21am    
Hi swapnil, The you have done the code is working correct, as you are assigning the timevalue on butoon click each time you login new time value will be assigned and stored in session, what is that you are looking for ?

1 solution

In development environment when you make changes in your code and recompile.. sessions are cleared on development server..make sure its not happening with you which checking time
 
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