title: ASP.net - Getting table index on html table when button clicked
body: <p>I have the following code which populates an html table from data retrieved from Parse.com.</p>
  
  <p>As you can see the table has buttons in it which are generated as the table gets populated. When clicked, obviously the buttons need to perform an action related to that row of data. </p>
  
  <p>Can anybody help me with the click event please, specifically getting the row index?</p>
  
  <p>At the moment the click event doesn't even seem to trigger the "response.Write" alert. (i'm very new to asp.net though)</p>
  
  <pre><code>using Parse;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.HtmlControls;
  using System.Web.UI.WebControls;
  
  namespace FrogPointCMS
  {
      public partial class Beacons : System.Web.UI.Page
      {
          string merchantName;
          string myMerchantID;
          ParseObject merchantObject;
  
          protected void Page_Load(object sender, EventArgs e)
          {
  
              merchantName = Request.QueryString["user"];
              myMerchantID = Request.QueryString["merchantID"];
  
              merchantObject = (ParseObject)Session["Merchant"];
  
              getBeacons();
  
  
          }
  
          public async void getBeacons()
          {
               MyParseQueries myQuery = new MyParseQueries();
  
               var myBeacons = await myQuery.getMyBeacons(merchantObject);
  
              foreach (ParseObject beacon in myBeacons)
              {
                  string aliasName = "";
                  string offerType = "N/A";
                  string offerTitle = "";
                  string offerDescription = "";
  
                   var merchantOb = beacon.Get&lt;ParseObject&gt;("merchantObjectId");
                   var merchantID = merchantOb.ObjectId;
  
                   if (merchantID == myMerchantID)
                   {
                       if (beacon.ContainsKey("contentObjectID"))
                       {
                           ParseObject content = beacon.Get&lt;ParseObject&gt;("contentObjectID"); // get the content object from parse.
                           offerType = content.Get&lt;string&gt;("offerType");
                           offerTitle = content.Get&lt;string&gt;("offerTitle");
                           offerDescription = content.Get&lt;string&gt;("offerDescription");
                       }
  
                       aliasName = beacon.Get&lt;string&gt;("aliasName");
  
                       Button assignNameBtn = new Button();
                       assignNameBtn.ID = "assignName";
                       assignNameBtn.Text = "Assign Name";
                       assignNameBtn.Click += assignNameBtn_Click;
  
                       Button assignActionBtn = new Button();
                       assignActionBtn.ID = "assignAction";
                       assignActionBtn.Text = "Assign Action";
  
                       var tr = new HtmlTableRow();
                       var checkBox = new HtmlTableCell();
                       var tableCellName = new HtmlTableCell();
                       var tableCellButton1 = new HtmlTableCell();
                       var tableCellButton2 = new HtmlTableCell();
                       var tableCellAction = new HtmlTableCell();
  
                       checkBox.InnerHtml = "&lt;input  type=\"checkbox\"/&gt;";
                       tableCellName.InnerText = aliasName;
                       tableCellButton1.Controls.Add(assignNameBtn);
                       tableCellButton2.Controls.Add(assignActionBtn);
                       tableCellAction.InnerText = offerType + " - " + offerTitle + " - " + offerDescription;
  
                       tr.Cells.Add(checkBox);
                       tr.Cells.Add(tableCellName);
                       tr.Cells.Add(tableCellButton1);
                       tr.Cells.Add(tableCellAction);
                       tr.Cells.Add(tableCellButton2);
  
                       beaconTable.Rows.Add(tr);
                   }
  
              }
  
          }
  
          void assignNameBtn_Click(object sender, EventArgs e)
          {
              Response.Write("&lt;script type=\"text/javascript\"&gt;alert('Button clicked');&lt;/script&gt;");
  
              var btn = (Button)sender; // testing 
  
              HtmlTableRow row = (HtmlTableRow)btn.NamingContainer; //testing
  
  
          }
      }
  }
  </code></pre>