tags:

views:

28

answers:

1

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?

+3  A: 

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

Dave Swersky
I see. Looking into your answer further I found a chart of the life cycle at http://msdn.microsoft.com/en-us/library/ms178472.aspx that was helpful and seems to support what you're saying as far as when IsPostBack becomes available. I need to set some variables up for use in the the Page_PreInit section, so I either need to put all that code in there, or just figure on not haveing IsPostBack available. Thanks for your help.
Chad