title: Setting OnClick on button in html table dynamically
body: <p>I'm creating a table dynamically, each row will contain a button and this button is going to call a function, each button will handle different parameters, for example, </p>
  
  <pre><code>    string Parameter1 = "MyValue";
      string Parameter2 = "MyOthervalue";
  
      HtmlInputButton input = new HtmlInputButton();
      input.ID = "Button1";
      input.Value = "button";
      input.Attributes.Add("onclick", "MyFunction(" + Parameter1 + "," + Parameter2 + ");");
  
      td = new HtmlTableCell();
      td.Align = "center";
      td.Controls.Add(input);
      tr.Cells.Add(td);
  </code></pre>
  
  <p>When user clicks the button I need to run MyFunction and then refresh the page to see the changes. </p>
  
  <p>I know that maybe I could open a second page and send the parameters in the URL, but I'd like to use the code in the same page and then reload the page. </p>
  
  <p>What's the best approach. </p>
  
  <p>Thanks,</p>
  
  <p>EDIT. </p>
  
  <p>I was able to solve it in the following way:</p>
  
  <pre><code>    input = new Button();
      input.Text = "Click Me";
      input.CommandArgument = "3|Parameter3";
      input.Command += new CommandEventHandler(Button_Handler);
  
      td = new HtmlTableCell();
      td.Align = "center";
      td.Controls.Add(input);
  
      tr.Cells.Add(td);
      tbTable.Rows.Add(tr);
  
  
  
  public void Button_Handler(object sender, CommandEventArgs e)
  {
      Button mybutton = (Button)sender;
      string[] Parameters = e.CommandArgument.ToString().Split('|');
      mybutton.Text = Parameters[0] + "-" + Parameters[1];
      //Call MyFunction(Parameters[0], Parameters[1]);
  
  }
  </code></pre>