简体   繁体   English

我可以从BasePage使用Page.IsPostBack吗?

[英]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. 我有一个Web表单页面Default.aspx,该页面继承自我创建的BasePage类,而BasePage类又继承自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. BasePage.BasePage() (构造函数)中,如果我们不做回发,我想做些事情。 So I put the standard 所以我把标准

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

However, Page.IsPostBack always returns false, even when I am really posting back. 但是,即使我真的发回, Page.IsPostBack总是返回false。

My question, then, is this just a limitation of BasePage not being able to see the IsPostBack variable on the page level? 那么,我的问题是对BasePage的限制,无法在页面级别看到IsPostBack变量?

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? 还是我想念HttpContext.Current.Request而不是页面级别的Request时,我是否缺少其他内容?

Don't put it in the constructor. 不要将其放在构造函数中。 The IsPostBack value is valid within the lifecycle events PreInit through Load. IsPostBack值在生命周期事件“通过加载进行PreInit”中有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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