Click here to Skip to main content
15,117,549 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
Hi, I have a class function as following & I would like to use this class to be called into my master page. Then, doing login & logout time saved of the page into my database.

C#
namespace LogInLogOut
    {
        public partial class LogInLogOut : System.Web.UI.Page
       {        
           public static void updateLogoutTime(string username, string pcname, string module)
            {
              String connectionString = ConfigurationManager.ConnectionStrings["VSConfigConnectionString"].ConnectionString;
                SqlConnection connection = new SqlConnection(connectionString);
                SqlCommand cmd = new SqlCommand("UPDATE [Access]  set LogOutDate =  '" + DateTime.Today.ToString("dd/MM/yyyy") + "', LogOutTime =  '" + DateTime.Now.ToString("HH:mm:ss") + "' WHERE LoginID ='" + username + "' AND ModuleID = '" + module + "' AND comptname ='" + pcname + "' AND LogOutDate= ' '", connection);
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();
                cmd.Connection.Dispose();
            }
         }
    }


Here is the code in master page for doing popup message, but I have no idea to write the call function for calling the upper class into my master page. Hope anyone can assist me for this problem. Thank you.

C#
protected void Page_Load(object sender, EventArgs e)
     {
         string csname = "timeoutWarning";
         Type cstype = this.GetType();
         if (!Page.ClientScript.IsStartupScriptRegistered(cstype, csname))
         {
             string strconfirm = "<script>" +
                 "window.setTimeout('SessionTimeOutHandler()', 10000);" +
                 "function SessionTimeOutHandler() { " +
                 "alert('Your login session is expired');" +
                 "function(){ update(document.LogInLogOut('lblUserName.Text', 'lblComputerName.Text', 'UR')); } " +
                "window.location='../login.aspx';" +
                 " } </script>";
             Page.ClientScript.RegisterStartupScript(cstype, csname, strconfirm, false);
         }
 }
Posted
Comments
   
What does it mean: "call a class"? ..."call from file"? :-)
--SA
Nguang Sing Ping 8-Aug-12 0:34am
   
is calling class function from a cs file.

1 solution

If your objective is to save the user session logout date&time means you could do that in Global.asax file where you have to write like the following

C#
void Session_End(Object sender, EventArgs E) {
   //Your method logic goes here.
}


and set your session timeout(default is 20 Minutes) in the web.config file as

C#
<sessionstate timeout="10000"></sessionstate>
   
Comments
Nguang Sing Ping 7-Aug-12 0:49am
   
sorry that if without using the Global.asax is there any other way to do it?
Actually at the begining I used
LogInLogOut.LogInLogOut.updateLogoutTime(lblUserName.Text, lblComputerName.Text, "UR");
but it didn't saved the correct logout time. So I'm thought I could write it in javascript as I shown in my question:
function(){ update(document.LogInLogOut('lblUserName.Text', 'lblComputerName.Text', 'UR')); }
But fail to work as well. So how am I going to solve it?
   
Then you have to try with Jquery + ajax.

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