Honey Chawla

Honey Chawla

  • NA
  • 638
  • 494k

How to Count Button Click in Asp.Net

Aug 10 2012 1:14 AM
<script runat="server">

protected void Button_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.Text = (Int32.Parse(btn.Text) + 1).ToString();
}

</script>


This is a demonstration of button counter. every time we click the button it is incremented.<br />


First Counter:
<asp:Button
id="Button1"
Text="0"
OnClick="Button_Click"
Runat="server" />

<br /><br />

Second Counter:
<asp:Button
id="Button2"
Text="0"
OnClick="Button_Click"
Runat="server" />


Answers (8)