I'm working in a web application aspx and C#. I have two procedures in code behind.

protected void Button1_Click(object sender, EventArgs e)
{
...
int totalCost=1000;
Label7.Text = totalCost.ToString();
}

i have this code behind in in button2

protected void Button2_Click(object sender, EventArgs e)
{
...
int  bCost=Convert.ToInt32(Label7.Text);
}

I first click button 1 and all is OK when I click button 2 the exeption is thrown at

int  bCost=Convert.ToInt32(Label7.Text);

is
Input string was not in a correct format.

Why I can't use the Label7 value from second procedure.

It shouldn't normally happen. Check the value of the Label7 in Button2_Click when converting to int. Something must be changing the value of label7.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.