动态创建按钮,页面刷新后的问题
我在页面初始化时动态加了两个按钮,然后在onclick事件改变当前按钮的样式,代码如下,但为什么每次一点后就刷新了,那两个按钮不见了,如果去掉 "if(!IsPostBack) ",每次样式就不会变,就是从新初始化了这些按钮,请问怎么样去保存这些动态创建的按钮,并每次点击时改变点击的按钮的样式啊.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HtmlTableCell cell = new HtmlTableCell();
cell.ID = "cell " + tmpName;
cell.Attributes[ "class "] = "TopBorder ";
LinkButton btn = new LinkButton();
btn.ID = "btn " + tmpName;
btn.Click += new EventHandler(btn_Click);
cell.Controls.Add(btn);
TopTable.Rows[0].Cells.Add(cell);
cell = new HtmlTableCell();
cell.ID = "cell " + tmpName;
cell.Attributes[ "class "] = "TopBorder ";
LinkButton btn = new LinkButton();
btn.ID = "btn " + tmpName;
btn.Click += new EventHandler(btn_Click);
cell.Controls.Add(btn);
TopTable.Rows[0].Cells.Add(cell);
}
}
void btn_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
HtmlTableCell cell = (HtmlTa