title: make dynamically generated href call a c# function
body: <p>I am trying to build a dropdown as below.</p>
  
  <p><img src="https://i.stack.imgur.com/tt5pm.png" alt="this is the menu that I need to generate"></p>
  
  <p>I am generating html ul &amp; li tags as below and works fine. However, everytime there is an anch tag (see the in-line comment); I need to be able to call a function and pass a text that was clicked. How can I do this? </p>
  
  <pre><code>        foreach (var productType in productTypesNames.Keys)
          {
              var li = new HtmlGenericControl("li");
              nav.Controls.Add(li);
              var ul = new HtmlGenericControl("ul");
  
              var anchor = new HtmlGenericControl("a");
              anchor.Attributes.Add("href", "#");
  
              foreach (var pName in productTypesNames[productType] )
              {
                  var subLi = new HtmlGenericControl("li");
                  var anch = new HtmlGenericControl("a");
                  anch.Attributes.Add("href", "#");
                  //**THIS NEEDS TO CALL A C# FUNCTION AND PASS pName; instead of #**
                  anch.InnerHtml = pName;
                  subLi.Controls.Add(anch);
                  ul.Controls.Add(subLi);
              }
              anchor.InnerHtml = productType;
              li.Controls.Add(anchor);
              li.Controls.Add(ul);
          }
  </code></pre>