window.setInterval(function () {
var currenttime = $('#Label1').val();
var duration = $('#Label2').val();
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "videoplayer.aspx/UpdateTimer_Tick",
data: "{'currenttime':'" + currenttime + "','duration':'" + duration + "'}",
async: false,
success: function (response) {
},
error: function () {
}
});
}, 3000);
And C# function
[WebMethod]
[ScriptMethod]
protected static void UpdateTimer_Tick(string currenttime,string duration)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("Insert into currenttimedata (currenttime,duration) values(@name,@age)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@name", currenttime);
cmd.Parameters.AddWithValue("@age", duration);
cmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
throw(ex);
}
}