Hi micah,
Check this example. Now please take its reference and correct your code.
HTML
<asp:Label ID="lblCount" runat="server" />
<asp:Button Text="Increament counter" OnClick="IncreamentCounter" runat="server" />
Code
C#
protected void IncreamentCounter(object sender, EventArgs e)
{
int counter;
if (ViewState["Count"] != null)
{
counter = Convert.ToInt32(ViewState["Count"]);
}
else
{
counter = 0;
}
counter = counter + 1;
ViewState["Count"] = counter;
this.lblCount.Text = counter.ToString().PadLeft(3, '0');
}
VB.Net
Protected Sub IncreamentCounter(ByVal sender As Object, ByVal e As EventArgs)
Dim counter As Integer
If ViewState("Count") IsNot Nothing Then
counter = Convert.ToInt32(ViewState("Count"))
Else
counter = 0
End If
counter = counter + 1
ViewState("Count") = counter
Me.lblCount.Text = counter.ToString().PadLeft(3, "0"c)
End Sub
Screenshot