1
Below are two examples of my codes, I have a text box weight that the user needs to put some weight, and can not be 0. In the first code below, he does the checking though, he runs the rest of my code where I commented, which was not meant to happen. Since if it’s 0 or blank, it should stop the code. In the second code it works when I use 0, but if it is empty of the error by trying to transform to int since there is nothing in the textbox.
Someone has 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;
{
This opens keys after
LBL_Peso.Visible = false;
is there really? It wasn’t even to compile with this. Anyway, to fix your error of running the rest of the code, just put all of it inside an Else.– Luis Henrique