Hi DPrasad,
Make the method as public with static and remember to decorate the method with WebMethod in order to call with jQuey Ajax.
Like below.
[WebMethod]
public static void InsertLogOutTime()
{
string ip = "";
string AT = "";
if (Session["ip"] != "" || Session["ip"] != null)
{
ip = Session["ip"].ToString();
}
else
{
ip = "N/A";
}
if (Session["arrivalTime"] != "" || Session["arrivalTime"] != null)
{
AT = Session["arrivalTime"].ToString();
}
else
{
AT = "N/A";
}
string constr = ConfigurationManager.ConnectionStrings["CS"].ConnectionString;
string sqlStatment = string.Format(@"INSERT INTO [dbo].[VISIT_DURATION]([IP_ADDRESS]
,[LEAVING_TIME]
,[ARRIVAL_TIME]) VALUES(@ip,@LeavingTime,@ArrivalTime)");
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sqlStatment, con))
{
con.Open();
cmd.Parameters.AddWithValue("@ip", ip.ToString());
cmd.Parameters.AddWithValue("@LeavingTime", DateTime.Now.ToLongTimeString());
cmd.Parameters.AddWithValue("@ArrivalTime", AT.ToString());
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Also make sure the page name in the url: "saveLeavingTime.aspx/InsertLogOutTime", is correct.