Below are two examples of my codes, I have a text box weight that the user needs to put some weight on, and can not be 0. In the first code below, it does the check though, it runs the remainder of my code where I commented, which was not to happen. Since it is 0 or blank, you should stop the code. In the second code it works when I use 0, however if it is blank the error for trying to transform to int since there is nothing in the textbox.
Does anyone have a solution for this?
CODE 1
protected void BT_Cadastrar_Click(object sender, EventArgs e)
{
if (TB_Peso.Text.Trim().ToString() == "")
LBL_Peso.Visible = true;
else
LBL_Peso.Visible = false;
{
int zero = Int32.Parse(TB_Peso.Text);
if (zero == 0)
LBL_Peso.Visible = true;
// meu código continua
}
}
CODE 2
protected void BT_Cadastrar_Click(object sender, EventArgs e)
{
int zero = Int32.Parse(TB_Peso.Text);
if (TB_Peso.Text.Trim().ToString() == "" || zero == 0)
LBL_Peso.Visible = true;
else
LBL_Peso.Visible = false;
{