Simple question about C# if else statement

Posted by ilkdrl on Stack Overflow See other posts from Stack Overflow or by ilkdrl
Published on 2010-05-07T22:41:58Z Indexed on 2010/05/07 23:28 UTC
Read the original article Hit count: 204

Filed under:

Iam doing a simple website and when i press button, i should see weight in label.. i see but if text.maxlenght > 6, i should see ERROR message in same label but repeat see weight in label. How can i solve this problem?

protected void Button1_Click(object sender, EventArgs e)
{
    double sayi1, sayi2, sayi3, hesap, sonuc;

    sayi1 = Convert.ToDouble(Tb1.Text);
    sayi2 = Convert.ToDouble(Tb2.Text);
    sayi3 = Convert.ToDouble(Tb3.Text);

    if (Tb1.MaxLength > 6 || Tb2.MaxLength > 6)
    {
        lbl1.Text = "ERROR.";

    }
    else
    {
        hesap = (((sayi1 - ((sayi1 - sayi2) / 2)) * ((sayi1 - sayi2) / 2)) / 40);
        sonuc = (hesap * sayi3) / 100;
        lbl1.Text = sonuc.ToString() + "kg";
    }


}

© Stack Overflow or respective owner

Related posts about c#