在ascx里,Page_Load里的方法可以只被执行一次吗?
比如我在5个页面里嵌入了这个ascx,但是我只想在其中一个页面打开的时候执行Page_Load
里的方法。

解决方案 »

  1.   

    假设这个页面是Page3.
    判断 if (this.Page is Page3) { execute ...}
      

  2.   

    你可以传个参数给 ascx在pageload里判断当取到这个参数时 执行pageload内的操作
      

  3.   


     /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && Request.QueryString["XX"]="exec")
            {
               .......
            }
        }