You must have to place that code in page_load
or page_init
event.
protected void Page_Load()
{
Button ButtonChange = new Button();
ButtonChange.Text = "Change";
ButtonChange.ID = "change_" + i.ToString();
ButtonChange.Font.Size = FontUnit.Point(7);
ButtonChange.ControlStyle.CssClass = "button";
ButtonChange.Click += new EventHandler(test);
}
Read MSDN article – How to: Add Controls to an ASP.NET Web Page Programmatically?