Count every Buton clicks

oXX

New Member
the task is to count the number of clicks in a webform.here is the code.\[code\]public partial class _default : System.Web.UI.Page { int count = 1; private void Page_Load(object sender, System.EventArgs e) { Button btn = new Button(); btn.Text = "Click Me"; btn.Click += btn_Click; Label lbl = new Label(); form1.Controls.Add(btn); form1.Controls.Add(lbl); } protected void btn_Click(object sender, EventArgs e) { count++; //Label1.Text = count.ToString(); } }\[/code\]the problem is that lbl is not recognised inside btn_Click() ... i cant figure it out... can any one suggest?
 
Back
Top