title: Asp.net web form passing argument on button click generated inside loop
body: <p>I am generating buttons inside <strong>foreach</strong> loop</p>
  
  <pre><code>&lt;% foreach (var myObject in myObjectList)
     {
  %&gt;
         &lt;b&gt;Text field&lt;/b&gt;: &lt;%= myObject.Text%&gt;&lt;br&gt;                     
         &lt;asp:Button ID="" runat="server" OnClick="WaitQueueDeleteBtn_Click" CommandArgument="pass myObjectText" Text="Delete"/&gt;
  
  &lt;% } %&gt;
  </code></pre>
  
  <p>It seems that I cannot use <code>myObject</code>'s field inside <code>CommandArgument</code> however <code>myObjectList</code> is accessible</p>
  
  <p>i.e </p>
  
  <pre><code>&lt;asp:Button ID="" runat="server" OnClick="WaitQueueDeleteBtn_Click" CommandArgument="&lt;%#myObjectList.Count%&gt;" Text="Delete"/&gt;
  </code></pre>
  
  <p>The above statement would work but the one below would not</p>
  
  <pre><code>&lt;asp:Button ID="" runat="server" OnClick="WaitQueueDeleteBtn_Click" CommandArgument="&lt;%#myObject.Text %&gt;" Text="Delete"/&gt;
  </code></pre>
  
  <p>Any idea why? And how can I pass <code>myObject</code>'s field values as <code>CommandArgument</code>?</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>Button method in class</p>
  
  <pre><code>protected void WaitQueueDeleteBtn_Click(object sender, EventArgs e)
  {
  
  }
  </code></pre>