I'm calling a webService.asmx
using Jquery
and inside that service i'm retrieving a usercontrol
control's values to save them in the database but the user control has thrown a NullReferenceException
here is Ajax
call
function SaveEdit()
{
$.ajax({
type: "POST",
url: "Services/RatiosSettingsService.asmx/UpdateRatios",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) { }
});
}
and this is WebService
code
[WebMethod]
public void UpdateRatios()
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Crs2"].ConnectionString))
{
ADO ado = new ADO();
List<SqlParameter> parameters = new List<SqlParameter>();
ucOtherRatios2 obj = new ucOtherRatios2();
Dictionary<string, int> hs = obj.GetHsChks();
foreach (KeyValuePair<string, int> item in hs)
{
SqlParameter para = new SqlParameter(item.Key, item.Value);
parameters.Add(para);
}
con.Open();
ado.CUDSp("UpdateRatios", "spUpdateClientRatios",parameters,con);
con.Close();
}
}
and here is where the exception happened inside usercontrol method that retrieve the controls values
public Dictionary<string, int> GetHsChks()
{
Dictionary<string, int> chks = new Dictionary<string, int>();
chks.Add("@siAnalysisOtherRatiosHistorical1", Convert.ToInt32(chkOthWcHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical2", Convert.ToInt32(chkOthWiHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical3", Convert.ToInt32(chkOthTlgHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical4", Convert.ToInt32(chkOthEiHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical5", Convert.ToInt32(chkOthEcHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical6", Convert.ToInt32(chkOthEicHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical7", Convert.ToInt32(chkOthEsHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical8", Convert.ToInt32(chkOthEtHs.Checked));
return chks;
}
it says that checkbox is null