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.
精彩评论