I am calling webmethod in asmx.cs file from ajax javascript by click event of button in asp.net c#. Now, in this circle button click event working fine, webmethod event also fired perfectly with passing correct data in parameter but after the webmethod call alert success getting undefined output.
Here is my code,
$("#btnGetStock").click(function (e) {
var label = document.getElementById("<%=txt_labelno.ClientID%>").value;
$.ajax({
type: "POST",
url: "FillGridMethod.asmx/QuotationList",
data: JSON.stringify({ labelno: label }),
dataType: "text",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data["ItemType"]);
}
});
});
Here is the webmethod code,
[WebMethod(enableSession: true)]
public void QuotationList(string labelno)
{
if (HttpContext.Current.Session["BranchId"].ToString() == null)
{
Server.Transfer("Index.aspx");
return;
}
var quotation = new List<QuotationModel>();
string constr = cn.ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
qryFillGrid = " select max(stock.ItemType) as ItemType, sum(chrgtotalprice) as chrgtotalprice from tbl_StockRunning stock " + System.Environment.NewLine;
var cmd = new SqlCommand(qryFillGrid, con);
con.Open();
var dr = cmd.ExecuteReader();
while (dr.Read())
{
var quotationModel = new QuotationModel
{
ItemType = dr[0].ToString().Trim(),
TotalCharge = Convert.ToDecimal(service.IfNullThen(dr[1], 0))
};
quotation.Add(quotationModel);
}
}
var js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(quotation));
}