Hello,
I am trying to make a particular label multiply its value and display according to the value of another label.
For instance, If I have two labels (label1 and label2), then label1 has a value of 1 and the value of label2 of is 20.
If the value of label1 increases to 2, then the value of label2 should multiply and increase to 40.
If the value of label1 increases to 3, then the value of label2 should also multiply and increase to 60.
Here is my HTML and Code
HTML
<div>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
CODE
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Label1.Text = (i++).ToString();
Label2.Text = ("20").ToString();
}
}
private double i
{
get
{
return ViewState["i"] != null ? (double)ViewState["i"] : 1;
}
set
{
ViewState["i"] = value;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = (i++).ToString();
}