c# - Null Reference Exception error in ASP.net -


this question has answer here:

i have port application windows forms asp.net

everything works fine untill try add data of sale form using form. in windows form works fine, when try in asp "null reference exception unhandeled user code

this pops when try access "add new sale from" main form.

the code in "add sale form" is:

public partial class addsaleform : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {      }      public sale getdata()     {          return new sale(idtextbox.text, datetextbox.text, locationtextbox.text, convert.todouble(pitchcosttextbox.text), convert.toint32(numpitchestextbox.text), charitycheckbox.checked, charitynametextbox.text, cateringcheckbox.checked);     } 

any idea of goes wrong , can fix it?

here constructor:

    namespace antiquesale {     [serializable]     public class sale : icomparable<sale>     {         private string saleid;          public string saleid         {           { return saleid; }           set { saleid = value; }         }          private string saledate;         private string location;         private double pitchcost;         private int numpitches;         private bool charity;          public bool charity         {             { return charity; }             set { charity = value; }         }          private string charityname;         private bool catering;          public sale(string saleid,                         string saledate,                         string location,                         double pitchcost,                         int numpitches,                         bool charity,                         string charityname,                         bool catering)         {             this.saleid = saleid;             this.saledate = saledate;             this.location = location;             this.pitchcost = pitchcost;             this.numpitches = numpitches;             this.charity = charity;             this.charityname = charityname;             this.catering = catering;         }          public override string tostring()         {             string str;              string charitystring;             string cateringstring;             string charitynamestring;              if (charity)             {                 charitystring = "yes";                 charitynamestring = charityname;             }             else             {                 charitystring = "no";                 charitynamestring = "n/a";             }              if (catering)             {                 cateringstring = "yes";             }             else             {                 cateringstring = "no";             }              str = string.format("{0}: {1}: {2}: {3}: {4}: {5}: {6}: {7}",                                     saleid,                                     saledate,                                     location,                                     pitchcost,                                     numpitches,                                     charitystring,                                     charitynamestring,                                     cateringstring);             return str;         }          public int compareto(sale sale)         {             return this.saleid.compareto(sale.saleid);         }     } 

the constructor not designed me, starting code received needed modify asp.

your problem 1 of these 2 lines of code:

  1. verify pitchcosttextbox.text not null or empty in line convert.todouble(pitchcosttextbox.text) doing instead:

    double pitchcost = 0.0; if(!string.isnullorempty(pitchcosttextbox.text)) {     pitchcost = convert.todouble(pitchcosttextbox.text); } 
  2. verify numpitchestextbox.text not null or empty in line convert.toint32(numpitchestextbox.text).

    int numpitches = 0; if(!string.isnullorempty(numpitchestextbox.text)) {     numpitches = convert.toint32(numpitchestextbox.text); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -