写一个类(BasePage),继承自Page类,而页面后台继承自(BasePage),现在我有多个页面A.aspx,B.aspx,而A,B两个页面都有按钮,我想在BasePage类,拿到这些按钮,可以实现吗?

解决方案 »

  1.   

    反过来,BasePage类公共函数,传这些按钮的对象
      

  2.   

    this.Controls[0].FindControl("CLeft").Controls[0].FindControl("left");类似这样
      

  3.   

    试试public class BasePage : System.Web.UI.Page
        {
            override protected void OnInit(EventArgs e)
            {
                InitializeComponent();
                base.OnInit(e);
            }
            private void InitializeComponent()
            {
                this.Load += new System.EventHandler(this.Page_Load);
            }        protected void Page_Load(object sender, EventArgs e)
            {
                GetPageTextBox(this.Page.Controls);        }        public static void GetPageTextBox(System.Web.UI.ControlCollection controls)
            {
                foreach (System.Web.UI.Control control in controls)
                {
                    if (control.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
                    {
                        //其他操作
                    }
                }
            }
        }
      

  4.   

    反过来不行么?BasePage 定义函数,接收参数,Page_Load 或者 Page_PreInit的时候传按钮