创建页生命周期的preINIT事件动态控制? [英] Create Dynamic Controls in PreInit Event of Page Life Cycle?

查看:111
本文介绍了创建页生命周期的preINIT事件动态控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN说,创建页生命周期的preINIT事件动态控制。

MSDN says that create Dynamic Controls in PreInit Event of Page Life Cycle.

http://msdn.microsoft.com/en-us/library/ ms178472.aspx

为什么?

什么好处由preINIT事件创造出来的?

What advantage is derived by creating in PreInit Event?.

我见过code其中开发人员在Page_Load方法创建动态控制?

I have seen code where developers are creating dynamic controls in the Page_Load Method?

如果有什么区别呢?

问候

推荐答案

的Page_Load 如果您不需要担心保存的控制工作正常,的ViewState ,但如果你需要坚持吧,加载阶段是不是你应该添加这些控件。

Page_Load works fine if you don't need to worry about saving the controls' ViewState across postbacks, but if you need to persist it, the Load stage is not where you should add these controls.

动态控件必须在页面的控制层级中加载ViewState中之前就已存在。有前加载视图状态只有一个阶段 - 初始化。这意味着,如果你希望你的动态控件坚持视图状态,您必须在页面的初始化事件将它们添加到控制层次。

Dynamic controls must exist within the page's control hierarchy before the ViewState is loaded. There's only one stage before Load View State - Initialization. That means, if you want your dynamic controls to persist view state you must add them to the control hierarchy in the page's Init event.

http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/092904-1.aspx

但记住,你不能访问的ViewState 初始化事件,因为它尚未加载。所以,你需要使用不同的持久媒体如果需要存储的变量在回传(如会议)。

But mind that you cannot access the ViewState in Init event because it's yet not loaded. So you need to use a different persistence medium to store variables across postbacks(like Session) if required.

这篇关于创建页生命周期的preINIT事件动态控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆