{"id":42,"date":"2011-10-20T07:55:00","date_gmt":"2011-10-20T07:55:00","guid":{"rendered":"https:\/\/wdev-blog.azurewebsites.net\/index.php\/2011\/10\/20\/asp-page-en-control-lifecycle\/"},"modified":"2011-10-20T07:55:00","modified_gmt":"2011-10-20T07:55:00","slug":"asp-page-en-control-lifecycle","status":"publish","type":"post","link":"http:\/\/panahy.nl\/index.php\/2011\/10\/20\/asp-page-en-control-lifecycle\/","title":{"rendered":"ASP Page en Control Lifecycle"},"content":{"rendered":"<p>When I put a logging in a couple of override methods of a NameBox control and load the page containing the custom control I see the following:<br \/><code><br \/>STARTING: MCTS._70_515.Resources.NameBox.Page_Init<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnInit<br \/>STARTING: MCTS._70_515.Resources.NameBox.<b>Page_Load<\/b><br \/>STARTING: MCTS._70_515.Resources.NameBox.OnDataBinding<br \/>STARTING: MCTS._70_515.Resources.NameBox.get_LastName<br \/>STARTING: MCTS._70_515.Resources.NameBox.<b>OnLoad<\/b><br \/>STARTING: MCTS._70_515.Resources.NameBox.OnPreRender<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnUnload<br \/><\/code><\/p>\n<p>It is important to note that Page_Load is long before OnLoad method, similar to Page_Init versus OnInit.<\/p>\n<p>Next I click on the change button to post back to handle the event and I see the following:<br \/><code><br \/>STARTING: MCTS._70_515.Resources.NameBox.Page_Init<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnInit<br \/>STARTING: MCTS._70_515.Resources.NameBox.Page_Load<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnDataBinding<br \/>STARTING: MCTS._70_515.Resources.NameBox.get_LastName<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnLoad<br \/>STARTING: MCTS._70_515.Resources.NameBox.<b>ChangeRequestClicked<\/b><br \/>STARTING: MCTS._70_515.Resources.NameBox.OnPreRender<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnUnload<br \/><\/code><\/p>\n<p>Next, I add some similar loggging to the page that contains the control and see what happens when I load the page:<\/p>\n<p><code><br \/>STARTING: MCTS._70_515.Resources.NameBox.Page_Init<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnInit<br \/><span style=\"color: blue;\"> STARTING: MCTS._70_515.Resources._Default.Page_Init<br \/>STARTING: MCTS._70_515.Resources._Default.OnInit<br \/>STARTING: MCTS._70_515.Resources._Default.Page_Load<br \/>STARTING: MCTS._70_515.Resources._Default.OnLoad<\/span><br \/>STARTING: MCTS._70_515.Resources.NameBox.Page_Load<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnDataBinding<br \/>STARTING: MCTS._70_515.Resources.NameBox.get_LastName<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnLoad<br \/><span style=\"color: blue;\"> STARTING: MCTS._70_515.Resources._Default.OnPreRender<\/span><br \/>STARTING: MCTS._70_515.Resources.NameBox.OnPreRender<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnUnload<br \/><span style=\"color: blue;\"> STARTING: MCTS._70_515.Resources._Default.OnUnload<\/span><br \/><\/code><\/p>\n<p>So, The OnLoad method gets called after binding whereas the Page_Load is about before the binding. Obviously, if you need to initialize your data, you better put your code in OnInit rather that OnLoad or Page_Load.<br \/>Another important thig here is the PreRender methods. These methods get called after load has been completed and the data is assumed to be in place.<\/p>\n<p>Now let&#8217;s see what happens when I click a button on the control which causes a postback:<\/p>\n<p><code><br \/>STARTING: MCTS._70_515.Resources.NameBox.Page_Init<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnInit<br \/><span style=\"color: blue;\"> STARTING: MCTS._70_515.Resources._Default.Page_Init<br \/>STARTING: MCTS._70_515.Resources._Default.OnInit<br \/>STARTING: MCTS._70_515.Resources._Default.Page_Load<br \/>STARTING: MCTS._70_515.Resources._Default.OnLoad<\/span><br \/>STARTING: MCTS._70_515.Resources.NameBox.Page_Load<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnDataBinding<br \/>STARTING: MCTS._70_515.Resources.NameBox.get_LastName<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnLoad<br \/>STARTING: MCTS._70_515.Resources.NameBox.<b>ChangeRequestClicked<\/b><br \/><span style=\"color: blue;\"> STARTING: MCTS._70_515.Resources._Default.<b>ChangeName<\/b><br \/>STARTING: MCTS._70_515.Resources._Default.OnPreRender<\/span><br \/>STARTING: MCTS._70_515.Resources.NameBox.OnPreRender<br \/>STARTING: MCTS._70_515.Resources.NameBox.OnUnload<br \/><span style=\"color: blue;\"> STARTING: MCTS._70_515.Resources._Default.OnUnload<\/span><br \/><\/code><\/p>\n<p>Both event handlers in the control and in the page are called after all controls and the page has been loaded and the data is binded too, just before the rendering take place.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I put a logging in a couple of override methods of a NameBox control and load the page containing the custom control I see the following:STARTING: MCTS._70_515.Resources.NameBox.Page_InitSTARTING: MCTS._70_515.Resources.NameBox.OnInitSTARTING: MCTS._70_515.Resources.NameBox.Page_LoadSTARTING: MCTS._70_515.Resources.NameBox.OnDataBindingSTARTING: MCTS._70_515.Resources.NameBox.get_LastNameSTARTING: MCTS._70_515.Resources.NameBox.OnLoadSTARTING: MCTS._70_515.Resources.NameBox.OnPreRenderSTARTING: MCTS._70_515.Resources.NameBox.OnUnload It is important to note that Page_Load is long before OnLoad method, similar to Page_Init versus OnInit. Next I click &hellip; <a href=\"http:\/\/panahy.nl\/index.php\/2011\/10\/20\/asp-page-en-control-lifecycle\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;ASP Page en Control Lifecycle&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[34,36,37],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":0,"uagb_excerpt":"When I put a logging in a couple of override methods of a NameBox control and load the page containing the custom control I see the following:STARTING: MCTS._70_515.Resources.NameBox.Page_InitSTARTING: MCTS._70_515.Resources.NameBox.OnInitSTARTING: MCTS._70_515.Resources.NameBox.Page_LoadSTARTING: MCTS._70_515.Resources.NameBox.OnDataBindingSTARTING: MCTS._70_515.Resources.NameBox.get_LastNameSTARTING: MCTS._70_515.Resources.NameBox.OnLoadSTARTING: MCTS._70_515.Resources.NameBox.OnPreRenderSTARTING: MCTS._70_515.Resources.NameBox.OnUnload It is important to note that Page_Load is long before OnLoad method, similar to Page_Init versus OnInit. Next I click&hellip;","_links":{"self":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/42"}],"collection":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":0,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"wp:attachment":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}