title: Asp.Net button has no ID in javascript?
body: <p>I have some problems identifying an asp.net control in javascript. Here's a simple variant of my code, maybe you can see an error.</p>
  <p>This function creates a set of button + label, it can be called multiple times:</p>
  <pre><code>    private void AddRow(Panel pnl)
      {
          var myButton = new Button();
          myButton.Text = &quot;+&quot;;
          myButton.Attributes.Add(&quot;onclick&quot;, &quot;return MyJavascript();&quot;);
          myButton.Attributes.Add(&quot;somevariable&quot;, &quot;FOOBAR!&quot;);
  
          var lblAnzahl = new Label();
  
          pnl.Controls.Add(myButton);
          pnl.Controls.Add(lblAnzahl);
      }
  </code></pre>
  <p>This is the JS function the button calls:</p>
  <pre><code>            function MyJavascript(e) {
                  var sender = event.target || event.srcElement;
                  var somevar = sender.getAttribute(&quot;somevariable&quot;);
                  alert('somevar: ' + somevar);
                  alert('ID: ' + sender.id);
              }
  </code></pre>
  <p>The output is:</p>
  <blockquote>
  <p>somevar: FOOBAR!</p>
  <p>ID:</p>
  </blockquote>
  <p>So I guess I get the correct sender, but for some reason the ID is always empty. The easiest way for me would be, if I could somehow set the ID of button and label myself, so that I can give it an unique ID every time AddRow() gets called, so I can easily identify the button and of course the label that belongs to the button.</p>
  <p>What am I doing wrong?</p>