title: Attaching delegates to webBrowser html elements
body: <p>I am working on a windows form UserControl to render and interact with some HTML using the webBrowser control. Part of the content are some radio buttons that I need to capture click events from within my control. So in the DocumentCompleted event of the webBrowser I am attaching an onClick event to the radio buttons. All of this seems to work until I click on one of the radio buttons, it seems that only the final radio button is actually having the event attached, even though I have stepped through the code and the delegate is being attached for each radio button.</p>
  
  <p>This is the lambda I am using to attach the delegate to the HtmlElement. </p>
  
  <pre><code>void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  {
       foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("input"))
       {
           el.AttachEventHandler("onclick", (sender1, e1) =&gt; clickEventHandler(el, EventArgs.Empty));
       }
  }
  
  public void clickEventHandler(object sender, EventArgs e)
  {
      Guid answerId;
      var he = (HtmlElement)sender;
      if (Guid.TryParse(he.Id, out answerId))
          if (AnswerSelected != null)
              AnswerSelected(answerId);
   }
  </code></pre>
  
  <p>Delegate and event for AnswerSelected</p>
  
  <pre><code>public delegate void HtmlControlAnswerEventHandler(Guid answerId);
  public event HtmlControlAnswerEventHandler AnswerSelected;
  </code></pre>
  
  <p>Input button string.</p>
  
  <pre><code>&lt;input type=radio id="{0}" name="answer" value="{1}" /&gt;
  </code></pre>