I have 3 label controls on my web form (labelquantity, labelprice and labeltotalprice) and a button. When the page loads there are values for each of these labels, I made it that when I click on the button to add product the quantity will increase and the labeltotalprice will change. But when the page loads and i click on the button, it will return the label value to original state and when i clcik again it will add. But I want it to be that when I click on it once, it will add. For example, I have two products and the quantities of the product are 1 and 2. The price for 1 is 100 and price of 2 is 200. When I select the quantity as 2 the price will be 200. When I click on button it will take the quantity to 1 and the price to 100. Then when I click again it will add it to 2 and the price will also add to 200. I don't want to click twice before it adds. I want to click one time to add.
The values of all these labels are passed from previous page
HTML
<div>
<asp:label ID="labelquantity" runat="server" Text="QUantity"><asp:label>
<asp:label ID="labelprice" runat="server" Text="Price"><asp:label>
<asp:label ID="labeltotalprice" runat="server" Text="Total"><asp:label>
<asp:Button ID="btnadd" runat=server" Text="Add Product"/>
</div>
CODE:
private double i
{
get
{
return ViewState["i"] != null ? (double)ViewState["i"] : 1;
}
set
{
ViewState["i"] = value;
}
}
protected void btnadd_Click(object sender, EventArgs e)
{
labelquantity.Text = (i++).ToString();
labeltotalprice.Text = Convert.ToString(Convert.ToInt32(labelquantity.Text) * Convert.ToInt32(labelprice.Text)).ToString();
}