Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,
I have a label with a 90 value .When I click a button the label becomes 80 70 or 60,since it -= a variable connected to that label.It always counts the 90 and can't go below 80 70 60.This is the code :
C#
public partial class Default : System.Web.UI.Page
    {
        Powers powers = new Powers();
        int airElementalHealth = 90;
        int earthElementalHealth = 120;

        protected void Page_Load(object sender, EventArgs e)
        {
                airelementalHealthLabel.Text = airElementalHealth.ToString();
            ViewState.Add("airElementalhealth", health(airElementalHealth));
        }

        protected void usePowerButton_Click(object sender, EventArgs e)
        {
            //airElementalHealth = health(airElementalHealth);
           
                airelementalHealthLabel.Text = health(airElementalHealth).ToString();
            
        }

        private int health(int defendersHealth)
        {
                Random random = new Random();
                int damage = powers.powersArray[random.Next(3)];//It works but the health doesn t drop continuously after button clicks
                //the value changes always according int airElementalHealth = 90;
                defendersHealth -= damage;
            
            return defendersHealth;
        
        } 
    }
}

Thank you a lot for your time.
Posted
Updated 7-Oct-15 12:53pm
v2
Comments
CHill60 7-Oct-15 19:03pm    
Check for postback in the Page_Load?
George Tourtsinakis 8-Oct-15 4:52am    
I tried it with if (!Page.IsPostBack)no changes.Still same thing happens.
George Tourtsinakis 9-Oct-15 4:43am    
Any updates on this?Still couldn t find what I m doing wrong.Thank you again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900