简体   繁体   中英

Can I use Page.IsPostBack from BasePage?

I have a web form page Default.aspx, which inherits from a BasePage class that I created, which in turn inherits from System.Web.UI.Page. Very common setup.

Default : BasePage : System.Web.UI.Page

Within the BasePage.BasePage() (constructor), I want to do something if we're not doing a postback. So I put the standard

 if(!Page.IsPostBack)
 {
    // do stuff here
 }

However, Page.IsPostBack always returns false, even when I am really posting back.

My question, then, is this just a limitation of BasePage not being able to see the IsPostBack variable on the page level?

Or is there an extra piece I'm missing like when I must say HttpContext.Current.Request instead of just Request on the page level?

Don't put it in the constructor. The IsPostBack value is valid within the lifecycle events PreInit through Load.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM