One approach is to use the base page that you always use on your site. This will contain a variable called PageLoadComplete that you would set at the end of your PageLoad event. Then you can check the state of this variable inside your method.
public abstract class BasePage : System.Web.UI.Page { public bool PageLoadComplete { get; private set; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); PageLoadComplete = true; } }
If you want to access a variable from code external to your page, such as UserControl, you need to make it public and discard your page as BasePage.
public partial class MyUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { BasePage basePage = this.Page as BasePage; if (basePage != null && !basePage.PageLoadComplete) { throw new InvalidPageStateException(); } } }
source share