c# - System.FormatException when Converting a Value -


i receving error

system.formatexception

when click on button1 after entering persons details

public partial class _default : page {         protected void button1_click(object sender, eventargs e)     {         response.write("you have added person!");             person p = new person(textbox1.text, convert.toint32(textbox2.text),          textbox3.text, textbox4.text, convert.toboolean(dropdownlist1.selectedvalue), textbox5.text);             label1.text = (p.presentperson());     } } 

person class:

class person {     public int age { { return age; } set { age = value; } }     public string name { { return name; } set { name = value; } }     public string dob { { return dob; } set { dob = value; } }     public string telno { { return telno; } set { telno = value; } }     public bool gender { { return gender; } set { gender = value; } }     public string address { { return address; } set { address = value; } }     public string enterperson;      public person(string name, int age, string dob, string telno, bool gender, string address)     {         name = name;         age = age;         dob = dob;         telno = telno;         gender = gender;         address = address;     }      public string presentperson()     {         return enterperson = "name: " + name + "\n" + "age: " + age + "\n" +  "date of birth: "         + dob + "\n" + "telephone number: " + telno + "\n" + "gender: " + "\n" + "address: "         + address;     } } 

to avoid errors use validator textbox such regularexpression or custom. eg: \d+ age textbox. minimise errors. representation of male , female boolean, like:

bool gender = dropdownlist1.selectedvalue == "male" 

and pass constructor.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -