1 通用代码:
public static ArrayList BtnList(System.Web.UI.Control page)
...{
int nPageControls = page.Controls.Count;
ArrayList btnText = new ArrayList();
for (int i = 0; i < nPageControls; i++)
...{
foreach (System.Web.UI.Control control in page.Controls[i].Controls)
...{
if (control is Button)
...{
//btnText.Add(control.ID);
btnText.Add((control as Button).Text);
}
}
}
return btnText;
}
2 页面调用代码
protected void Page_Load(object sender, EventArgs e)
...{
ArrayList arrayList = new ArrayList();
System.Web.UI.Page page1 = (System.Web.UI.Page)HttpContext.Current.Handler;
arrayList = BtnCtrList.BtnList(page1);
foreach (object o in arrayList)
...{
ListBox1.Items.Add(o.ToString());
}
}