我google一下Page_preRender我們如何使用Page_PreRender而不是Page_Load中或可能是什麼地方,我們不能使用的Page_Load,並有使用Page_PreRender但我每次找地方,什麼樣的代碼只能在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上我們可以動態地創建控件,更改或分配我們在page_Load或Init之後無法使用的MasterPage或Theme。
但是,Page_PreRender是什麼,我們只能在Page_PreRender中做什麼。
謝謝,但「如果你想註冊一個客戶端腳本,這個好地方可能是Page_Render。「爲什麼不Page_Load – Azhar 2010-09-15 13:21:05
考慮」Page_Load「作爲使組件存在,然後使用該組件的客戶端腳本顯然只能在」Page_Load「之後註冊,因此後期階段...預渲染和渲染。 – loxxy 2010-09-15 15:09:58