I will show some examples that you can try in your own way.
The idea would be to create a list of buttons in which you would save the buttons created in btnCreateDynamic_click
you may have a method like this:
private Button CreateButton(string id, string name) { Button b = new Button(); b.Text = name; b.ID = id; b.Click += new EventHandler(Button_Click); b.OnClientClick = "ButtonClick('" + b.ClientID + "')"; return b; }
in btnCreateDynamic_click you might have something like:
Button b = CreateButton("dinamicBtn"+myDinamicButtonsList.Count.ToString(),"dinamicBtn"+myDinamicButtonsList.Count.ToString()); myDinamicButtonsList.add(b); and in the pageLoad for example you could do something like foreach(button btn in myDinamicButtonsList){ form1.Controls.Add(btn)); } List<Button> myDinamicButtonsList = new List<Button>();
myDinamicButtonsList should be stored somewhere from where it can be obtained after each request.
EDIT: when loading the page, you might have something like this:
if(Session["myDinamicButtons"] == null){ List<Button> myDinamicButtonsList = new List<Button>(); Session["myDinamicButtons"] = myDinamicButtonsList; } foreach(Button btn in Session["myDinamicButtons"] as List<Button>){ form1.Controls.Add(btn)); }
I have not tested it, but it should work.
also adds some information, the following may help.
Your event of clicking a button on the client will cause a postback to the page that will start the life cycle of the ASP.Net page. 
Your button click event on the server is PostBackEvent , and you must use the same CreateMyButton() call method that you used in the Load or Init events.
Saith source share