为什么不能在 Page.PreInit 事件之后动态应用主题和母版页?
1) 我认为主题只能在 Page.PreInit 事件处理程序中以编程方式设置,原因如下:
如果我们在 Page.Init 事件处理程序中设置主题,那么到那时 ViewState 就已经是跟踪,因此 Theme 应用的任何数据都会被跟踪并标记为脏数据(这会消耗大量带宽)?
如果我们在 Init 事件之后设置它,那么主题还可以覆盖应用于各个控件的反序列化 ViewState 数据吗?
还有其他原因导致Page.PreInit后无法设置主题吗?
2)另外,为什么Page.PreInit之后不能应用母版页?
谢谢
1) I assume Themes can be set programatically only inside Page.PreInit event handler due to the following reasons:
if we’d set a Theme inside Page.Init event handler, then by that time ViewState would already be tracked and thus any data applied by Theme would be tracked and marked as dirty ( which would consume lot of bandwidth ) ?
and if we’d set it after Init event, then Themes could also override deserialized ViewState data applied to individual controls?
Are there any other reasons why Themes can’t be set after Page.PreInit?
2) Also, why can't Master pages be applied after Page.PreInit?
thanx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据此:
http://odetocode.com/articles/450.aspx
本文还包括这个示例:
或者,我之前使用过的一种方法:
According to this:
http://odetocode.com/articles/450.aspx
The article also includes this example:
Or, an approach I've used before:
是的。主题包括皮肤,它可以指定控件的属性。这些属性需要在 Init 事件期间设置,因此需要在此之前选择所需的主题。
ViewState 跟踪可能是一个问题,但我认为与上述问题相比,这是一个小问题。
请注意,StyleSheetTheme(在我看来,优于常规主题)实际上是从页面上的重写属性设置的,而不是通过设置属性本身的值(除非您从 HttpModule 设置它)。
控件根据其在控件树中的位置(包括访问表单控件等)来确定其 ID 以及各种其他特征和属性。母版页相当于一组父控件,因此控件可以完全初始化自身,直到父结构就位。初始化发生在 Init 事件期间,因此需要在此之前选择母版页。
Yes. Themes includes skins, which can specify properties for controls. Those properties need to be set during the Init event, so the desired theme needs to be selected before then.
ViewState tracking may be an issue, but I think it's a minor one compared to the above.
Note that a StyleSheetTheme (preferable to a regular Theme, IMO), is actually set from an overridden property on the Page, not by setting the value of the property itself (unless you set it from an HttpModule).
Controls determine their IDs and various other characteristics and properties based on their location in the control tree (including things like accessing the form control, etc). A Master Page acts as what amounts to a set of parent controls, so controls can fully initialize themselves until that parent structure is in place. Initialization happens during the Init event, so the Master Page needs to be selected before then.