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,
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);
When user clicks the button I need to run MyFunction and then refresh the page to see the changes.
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.
What's the best approach.
Thanks,
EDIT.
I was able to solve it in the following way:
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]);
}