我在谷歌上搜索了 Page_preRender 我们如何使用 Page_PreRender 而不是 page_Load 或者我们不能使用 page_Load 并且必须使用 Page_PreRender 但我发现的每个地方的情况,
“ The point at which the objects are prerendered is the last time changes to the objects can be saved or persisted to viewstate. This makes the PreRender step a good place to make final modifications, such as changing properties of controls or changing Control Tree structure, without having to worry about ASP.NET making changes to objects based off of database calls or viewstate updates. After the PreRender phase those changes to objects are locked in and can no longer be saved to the page viewstate. The PreRender step can be overridden using OnPreRender
”。
但我无法理解哪些更改是我们无法在 page_Load 中进行而必须在 PreRender 中进行的。
据我所知,在 Page_PreInit 上,我们可以动态创建控件,更改或分配 MasterPage 或 Theme,这是我们在 page_Load 或 Init 之后无法做到的。
但是 Page_PreRender 有什么我们只能在 Page_PreRender 中做的事情。