I have written my webmethod in aspx.cs file , but when i call n.Nautilus() method in same page , i am unable to get the server side controls in Nautilus(), in this method controls becoming NULL , please find the reasons and solution to this problem as soon as possible.
[WebMethod]
public static string Execute4()
{
NewQuote2 n = new NewQuote2();
JavaScriptSerializer j = new JavaScriptSerializer();
string r = string.Empty;
var o = Observable.Start(() =>
{
// Thread.Sleep(7000);
PennStar pn = new PennStar();
r = j.Serialize(new { res = n.Nautilus() });
}, Scheduler.NewThread);
o.First();
// r = n.Nautilus();
return r;
}
public string Nautilus()
{
try
{
if (ddlLineCode.SelectedItem.Value == "GL")
{
deductible = Convert.ToInt32(ddlGLdeductible.SelectedItem.Text);
//ClassCode = Convert.ToInt32(ddlClassCode1.SelectedValues.ToString());
ClassCode = Convert.ToInt32(ddlClasscode.SelectedValue);
}
else if (ddlLineCode.SelectedItem.Value == "PP" || ddlLineCode.SelectedItem.Value == "PR")
{
deductible = Convert.ToInt32(ddlPropdeductible.SelectedValue);
}
string T = ddlTerritory.SelectedItem.Text;
QMSRatingEngine.Nautilus QR = new QMSRatingEngine.Nautilus();
ArrayList Result = new ArrayList();
if (LC == "GL")
{
QMSRatingEngine.NautilusAgents.ReturnGLRate gl = QR.GLRateObject(state, ED, deductible, ClassCode, ddlLimit.SelectedItem.Text, T);
Result.Add(gl);
getNautilusRatedata(gl);//this method code i can write the bellow
}
if (LC == "PP" || LC == "PR")
{
QMSRatingEngine.NautilusAgents.ReturnPropRate PRop = QR.PropertyRateObject(state, ED, ddlPropFormtype.SelectedItem.Text, ddlPropconstructiontype.SelectedItem.Text, ddlPropcovergetype.SelectedItem.Text, deductible, ddlPropuwscale.SelectedItem.Text, ddlPropprotectionclass.SelectedItem.Text, T);
Result.Add(PRop);
}
}
return lbltext.Text;
}
private void getNautilusRatedata(QMSRatingEngine.NautilusAgents.ReturnGLRate gl)
{
lblNautilusPremiumbasis.Text = GetPremiumBasisFormat(txtExposure.Text);
lblNautilusDeductible.Text = getCurrencyFormat(ddlGLdeductible.SelectedItem.Text);
string Type = ddlPremiumBasis.SelectedItem.Text;
decimal Premium = Convert.ToDecimal(gl.BaseRate_Prem.ToString());
decimal nautilusPremiumBasis = Convert.ToDecimal(txtExposure.Text);
decimal Prod = Convert.ToDecimal(gl.BaseRate_Prod.ToString());
decimal CalcPremium = 0, CalcProd = 0;
if (Type == "A - AREA" || Type == "M - ADMISSION" || Type == "U - UNITS" || Type == "O - OTHER")
{
CalcPremium = (Premium * nautilusPremiumBasis);
lblNautilusPremisesOp.Text = getCurrencyFormat(Math.Round(CalcPremium).ToString());
CalcProd = (Prod * nautilusPremiumBasis);
lblNautilusProductsCoop.Text = getCurrencyFormat(Math.Round(CalcProd).ToString());
}
if (Type == "C - TOTAL COST" || Type == "P - PAYROLL" || Type == "S - GROSS SALES")
{
CalcPremium = (Premium * nautilusPremiumBasis) / 1000;
lblNautilusPremisesOp.Text = getCurrencyFormat(Math.Round(CalcPremium).ToString());
CalcProd = (Prod * nautilusPremiumBasis) / 1000;
lblNautilusProductsCoop.Text =getCurrencyFormat(Math.Round(CalcProd).ToString());
}
lblNautilusGLPremium.Text = getCurrencyFormat(Math.Round((Math.Round(CalcProd) + Math.Round(CalcPremium))).ToString());
lblNautilusSubTotal.Text = getCurrencyFormat(Math.Round((Math.Round(CalcProd) + Math.Round(CalcPremium))).ToString());
lblNautilusGrandTotal.Text = getCurrencyFormat(Math.Round((Math.Round(CalcProd) + Math.Round(CalcPremium))).ToString());
//string jstablelattest = "moneyCoverage";
//ClientScript.RegisterClientScriptResource(this.GetType(), jstablelattest);
}
Because you are calling Nautilus()
function from public static string Execute4()
and because Execute4()
is a webmethod
and thus static
you are not able to find any controls as they are not static.
You should try to return the results and values from your webmethod
and do the operations like show/hide divs and other stuff with those results on the client side.