asp.net C#动态添加控件和控件的事件

int numOfPages = 10; protected void Page_Load(object sender, EventArgs e) { if (numOfPages > 1 && (string)Session["REVIEW"] != null && (string)Session["REVIEW"] == "REVIEW") { createButton(numOfPages); } } public void createButton(int numOfPages) { TableRow tblPageRow = new TableRow(); for (int i = 1; i <= numOfPages; i++) { TableCell tblPageCell = new TableCell(); System.Web.UI.WebControls.Button btnDisPage = new System.Web.UI.WebControls.Button(); //btnDisPage.Attributes.Add("onclik", "showRows(" + (i) + "," + disRows + "," + rowCount); btnDisPage.ID = "btnDis" + i; btnDisPage.Click += new EventHandler(btnDisPage_Click); btnDisPage.Text = "第" + (i) + "页"; tblPageCell.Controls.Add(btnDisPage); tblPageRow.Controls.Add(tblPageCell); } tblPageControl.Controls.Add(tblPageRow); } public void btnDisPage_Click(object sender, EventArgs e) { Response.Write("asdfsd"); } 控件能生成,但当我点击button以,显页好象重新加载。页面上的button都没了。 为什么?

当然了,,服务器控件都是回发到服务器 然后重新生成页面类
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答