I know about ASP.NET page life cycle but I'm confused. I have code here which creates buttons from database records. After I click on them, they dissapear with no code triggered. :( I know I have to recreate them in Page_Init but I don't know how. Please help! This is my code:
try
{
con.Open();
SqlDataReader myReader = null;
SqlCommand myCom = new SqlCommand("select ID,client from tposClient where CardNo='" + cNo + "'", con);
myReader = myCom.ExecuteReader();
Panel panel1 = new Panel();
panel1.Style["text-align"] = "Center";
panel1.Style["background"] = "blue";
div_login.Visible = false;
while (myReader.Read())
{
string b = myReader["client"].ToString();
string id = myReader["ID"].ToString();
Button btn = new Button();
btn.Text = b;
btn.ID = id;
btn.Style["width"] = "100px";
btn.Click += new EventHandler(btn_Click);
panel1.Controls.Add(btn);
panel1.Controls.Add(new LiteralControl("<br />"));
form1.Style.Add("display", "block");
form1.Controls.Add(panel1);
}
}
catch (Exception k)
{
Console.WriteLine(k.ToString());
}
finally
{
cmdselect.Dispose();
if (con != null)
{
con.Close();
}
}