title: Issues with onclick/onserverclick with buttons, HtmlButtons, and LinkButtons
body: <p>I'm having an issue with the functions to be called not firing off.</p>
  
  <p>I have moved from hardcoding the buttons on HTML, to using the add controls method in the cs; and I have shifted from using Button and HtmlButton to using LinkButton.  However none of these seem to work.  In <a href="https://stackoverflow.com/q/26185362/11035837">Onserverclick and onclick not work</a> Anup Sharma recommends using the LinkButton, and Keyvan Sadralodabai indicates that if the runat="server" is displayed in the insect element, then he control was set up wrong.</p>
  
  <p>So here's a stripped down simplified version of what I'm working with:</p>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Drawing;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.UI.HtmlControls;
      using System.Web.Services;
  
      using System.Data;
      using MySql.Data;
      using MySql.Data.MySqlClient;
  
      public partial class backCodeExper : System.Web.UI.Page
      {
  
          protected void saveRecord(string recordID, string buttonId, string dropdownId)
          {
  
              PlaceHolder db = Page.FindControl("TestingCS") as PlaceHolder;
              HtmlTable tbl = db.FindControl("TestTable") as HtmlTable;
              HtmlTableRow tr = tbl.FindControl("TheRow") as HtmlTableRow;
              HtmlTableCell tc = tr.FindControl("TheCell2") as HtmlTableCell;
              DropDownList ddl = tc.FindControl(dropdownId) as DropDownList;
  
  
              var status = ddl.SelectedValue.ToString();
  
              HttpContext context = HttpContext.Current;
              MySqlConnection conn = new MySqlConnection();
              conn.ConnectionString = "Server=localhost; Database********; User=********; Password=********; Port=3306"; 
              conn.Open();
              MySqlCommand cmd = new MySqlCommand();
              cmd.Connection = conn;
              cmd.CommandType = CommandType.StoredProcedure;
  
              cmd.CommandText = "updatetesttable";
              cmd.Parameters.AddWithValue("@param", status);
              cmd.ExecuteNonQuery();
          }
  
          protected void Page_Load(object sender, EventArgs e)
          {
              HtmlTable myTable = new HtmlTable();
              myTable.ID = "TestTable";
              myTable.BorderColor = "teal";
              myTable.BgColor = "black";
              TestingCS.Controls.Add(myTable);
  
              HtmlTableRow newRow;
              HtmlTableCell cell;
              DropDownList DropList;
              LinkButton saveButton;
  
              newRow = new HtmlTableRow();
              newRow.ID = "TheRow";
              cell = new HtmlTableCell();
              cell.ID = "TheCell1";
              DropList = new DropDownList();
              DropList.ID = "StatusDD";
              DropList.Items.Add(new ListItem("", "0"));
              DropList.Items.Add(new ListItem("A", "1"));
              DropList.Items.Add(new ListItem("B", "2"));
              DropList.Items.Add(new ListItem("C", "3"));
              cell.Controls.Add(DropList);
  
              newRow.Cells.Add(cell);
  
              cell = new HtmlTableCell();
              cell.ID = "TheCell2";
              cell.BgColor = "black";
              saveButton = new LinkButton();
              saveButton.ID = "saveButton";
  
              saveButton.CommandName = "saveRecord";
              saveButton.CommandArgument = "'1A',this.id,'StatusDD'";
              saveButton.BackColor=Color.Green;
              saveButton.ForeColor=Color.Cyan;
              saveButton.BorderColor=Color.Maroon;
              saveButton.Text = "Save";
              saveButton.Visible = true;
              cell.Controls.Add(saveButton);
              newRow.Cells.Add(cell);
              myTable.Rows.Add(newRow);
          }
      }
  </code></pre>
  
  <p>It loads the screen just fine with the simple dropdown and with the (unstylish) button (frankly the HtmlButton looks much nicer, but I'm aiming for functionality first).</p>
  
  <p>When I select an item from the dropdown and then click save, the screen appears to refresh, keeping the value of the dropdown the same as that which was selected. However, when I check the database, the procedure hasn't fired.  Additionally I cannot get this code segment <code>Response.Write("&lt;script&gt;alert('Hello');&lt;/script&gt;");</code> to execute when placed in the method/function saveRecord.</p>
  
  <p>Furthermore, when I run the debugging mode and put break points in saveRecord, none of them are hit.  </p>
  
  <p>After inspecting element, this is what I get:
  <a href="https://i.stack.imgur.com/aRkAB.png" rel="nofollow noreferrer">InspectElementResults</a></p>
  
  <p>Any suggestions? What am I missing?
  If I don't use LinkButton (or Button/HtmlButton with onServerClick) then I get errors saying the function isn't defined - which makes since as the function/method is define on the aspx.cs not the aspx within JS script tags.</p>