I have been through several posts of the same error, and I cant figure it out why it wont work for me.
I am trying to add multiple values in textboxes. Im starting with 2 textboxes to test, but my plan is to have a total of 10. But i keep getting this error. I have this event on each textbox. Ideas? IF needed, i can include my asp code.
protected void calculateLabs(object sender, EventArgs e)
{
string lab01 = TextBox1.Text;
string lab02 = TextBox2.Text;
int num1 = int.Parse(lab01);
int num2 = int.Parse(lab02);
int final = num1 + num2;
Label1.Text = final.ToString();
}
UPDATE, it works, but the exception still displays the message on the label, once i input the next values, the error goes away.
protected void calculateLabs(object sender, EventArgs e)
{
try
{
int num1 = Convert.ToInt32(TextBox1.Text);
int num2 = Convert.ToInt32(TextBox2.Text);
int final = num1 + num2;
Label1.Text = final.ToString();
}
catch(Exception ex)
{
Label1.Text = ex.Message;
}
}