title: Label Click Event
body: <p>I am trying too create a click event for a group of lables that are created dynamically like this:</p>
  
  <pre><code>private void AddLBL_Btn_Click(object sender, EventArgs e)
      {
          int ListCount = listBox1.Items.Count;
  
          int lbl = 0;
  
          foreach (var listBoxItem in listBox1.Items)
          {
              Label LB = new Label();
              LB.Name = "Label" + listBoxItem.ToString();
              LB.Location = new Point(257, (51 * lbl) + 25);
              LB.Size = new Size(500, 13);
              LB.Text = listBoxItem.ToString();
              Controls.Add(LB);
  
              lbl++;
          }
  
  
         LB.Click += new EventHandler(PB_Click);// error here
  
  
      }
  
      protected void LB_Click(object sender, EventArgs e)
      {
  
  
  
          webBrowser1.Navigate("http://www.mysite/" + LB);//Navigate to site on label
  
      }
  </code></pre>
  
  <p>I am getting an error:  "The name 'LB' does not exist in the current context" becauseI am creating LB within the loop and I am not smart enough to know how to declare LB so I can use it outside the loop.</p>
  
  <p>Additionally, I would like to pass to the label name (listBoxItem) on to the click event and have it where LB is in the WebBrowser call is.  Like: webBrowser1.Navigate("<a href="http://www.mysite/" rel="nofollow">http://www.mysite/</a>" + LB);//Navigate to site on label</p>