Refer below sample.
HTML
<asp:Button Text="Increament counter" OnClick="IncreamentCounter" runat="server" />
Value:
<asp:Label ID="lblCount" runat="server" />
<hr />
<asp:Button Text="Reset counter" OnClick="ResetCounter" runat="server" />
Code
protected void IncreamentCounter(object sender, EventArgs e)
{
int counter;
if (ViewState["Count"] != null)
{
counter = Convert.ToInt32(ViewState["Count"]);
}
else
{
counter = 0;
}
if (counter == 10)
{
counter = 1;
}
else
{
counter = counter + 1;
}
ViewState["Count"] = counter;
this.lblCount.Text = counter.ToString();
}
protected void ResetCounter(object sender, EventArgs e)
{
ViewState["Count"] = 1;
this.lblCount.Text = "1";
}
Screenshot