I got this error in my coding. And my code is given below and i need to pass the value to jquery to display data. What is this Error "An object reference is required for the non-static field, method, or property 'System.Web.UI.Control.Context.get'
" ?
[WebMethod]
public static string GetData()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["tempsConnectionString"].ConnectionString);
List<Glassrecord> glass = new List<Glassrecord>();
SqlCommand cmd = new SqlCommand("Select Prod_date,GreenTime,YellowTime from CrystalProdTracker ", con);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
Glassrecord glassrec = new Glassrecord();
glassrec.Date = sdr["Prod_date"].ToString();
glassrec.GreenTime = sdr["GreenTime"].ToString();
glassrec.YellowTime = sdr["YellowTime"].ToString();
glass.Add(glassrec);
}
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(glass));
}
and i also attached my jquery code with this post.How to proceed further
$.ajax({
url: "Add_Data.aspx/GetData",
method: "post",
datatype: "json",
data: '',
contentType: "application/json; charset=utf-8",
success :function(data){
$('$tblglass').dataTable(
{
data:data,
columns: [
{ 'data': 'Date' }, { 'data': 'GreenTime' }, { 'data': 'YellowTime' }
]
})
},
error: function (err) {
alert('Object Not Found');
}
});
};