title: Calling code behind function on dynamically generated href
body: <p>I am generating</p>
  
  <pre><code>&lt;a href="..."&gt;
  </code></pre>
  
  <p>dynamically in a code behind. When I click on the link it needs to run a sub from the code behind and also I need to know which link actually triggered that code behind function. </p>
  
  <p>This is my code behind (dynamically generating link) which is then displayed in div. I literally dump this (below code) as a string into a div:</p>
  
  <pre><code>      &lt;a href='#' 
             id='" + i.MemberId.ToString() + "' 
           Text='Click Me' 
  onServerClick='Check_Clicked' 
          runat="server"&gt;Click Me
       &lt;/a&gt;
  </code></pre>
  
  <p>And this is what I need to call:</p>
  
  <pre><code>Sub Check_Clicked(sender As Object, e As EventArgs)
      Me.div_result.InnerHtml = "TEST"
  End Sub
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Okay I added the following to my project:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          $('#inboxLink').click(function () {
              $.ajax({
                  type: 'POST',
                  url: 'inbox.aspx/GetSomething',
                  data: '{ test1: "somevalue" }',
                  ContentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function (data) {
                      alert("Success");
                  },
                  error: function (data) {
                      alert("Fail");
                  }
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>and then </p>
  
  <pre><code>&lt;System.Web.Services.WebMethod()&gt; _
  Public Shared Sub GetSomething()
      Me.div_result.InnerHtml = "TEST"
  End Sub
  </code></pre>
  
  <p>but there are more problems In the code behind </p>
  
  <blockquote>
    <p>'Me' is only valid within an instance method.</p>
  </blockquote>
  
  <p>so I am not sure the way I am approaching this problem might be wrong?</p>