page load precedence?
-
I have a LoginControl.ascx control and a ListItems.aspx page. Thay are placed in a MasterPage.master. I want the login control to be able to handle manual login as well automatic login from reading a cookie. Depening on the login result the list will display different set's of items. My problem is that when starting the ListItems.aspx the order of page load is: 1. ListItems_PageLoad (displaying a list of item based on NOT logged in state) 2. Master_PageLoad 3. LoginControl_PageLoad (automatically logging in the user) This means that the list is displayed on the NOT logged in state and I have to refresh the page to get the correct list. If I click logout in the logincontrol the list is rendered in the same way: 1. ListItems_PageLoad (displaying a list of item based on LOGGED IN state) 2. Master_PageLoad 3. LoginControl_PageLoad (logout the user) How should I go about programming to get the result I want? 1. ListItems_PageLoad (Initalize the login procedure) 2. Master_PageLoad 3. LoginControl_PageLoad (loggin out the user) 4. ListItems_PageLoad (complete the load, displaying a list of item based on LOGGED IN state) What am I missing?
-
I have a LoginControl.ascx control and a ListItems.aspx page. Thay are placed in a MasterPage.master. I want the login control to be able to handle manual login as well automatic login from reading a cookie. Depening on the login result the list will display different set's of items. My problem is that when starting the ListItems.aspx the order of page load is: 1. ListItems_PageLoad (displaying a list of item based on NOT logged in state) 2. Master_PageLoad 3. LoginControl_PageLoad (automatically logging in the user) This means that the list is displayed on the NOT logged in state and I have to refresh the page to get the correct list. If I click logout in the logincontrol the list is rendered in the same way: 1. ListItems_PageLoad (displaying a list of item based on LOGGED IN state) 2. Master_PageLoad 3. LoginControl_PageLoad (logout the user) How should I go about programming to get the result I want? 1. ListItems_PageLoad (Initalize the login procedure) 2. Master_PageLoad 3. LoginControl_PageLoad (loggin out the user) 4. ListItems_PageLoad (complete the load, displaying a list of item based on LOGGED IN state) What am I missing?
Use the Prerender event for some of this ( and if you're in .NET 2.0, there are even more events to choose from ), which will allow you to control the order. That is, the Page_load happens before the prerender, so putting something in the prerender, will force it to run later.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Use the Prerender event for some of this ( and if you're in .NET 2.0, there are even more events to choose from ), which will allow you to control the order. That is, the Page_load happens before the prerender, so putting something in the prerender, will force it to run later.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Thanx for the reply, I think you pointed me in the right direction. I found this article from Vivek Thakur. http://www.codeproject.com/useritems/lifecycle.asp[^] From where the page life-cycle-summary is:
1. OnPreInit 2. OnInit 3. (LoadViewState) ONLY ON POSTBACK 4. (LoadPostBackData) ONLY ON POSTBACK 5. Page_Load 6. (recusive Page_Load's for masterpages, other pages, controls) 7. Control Event Handlers (like Button1_Click()) 8. PreRender 9. (recusive PreRender's for mas...) 10. SaveViewState 11. Render 12. (recusive Render's for mas...) 13. Unload
...and from what I can gather, if dependent of the state of user controls placed in a masterpage, I should put the code in prerender as you said. How come all beginner tutorials are so focused on Page_Load then? -
Thanx for the reply, I think you pointed me in the right direction. I found this article from Vivek Thakur. http://www.codeproject.com/useritems/lifecycle.asp[^] From where the page life-cycle-summary is:
1. OnPreInit 2. OnInit 3. (LoadViewState) ONLY ON POSTBACK 4. (LoadPostBackData) ONLY ON POSTBACK 5. Page_Load 6. (recusive Page_Load's for masterpages, other pages, controls) 7. Control Event Handlers (like Button1_Click()) 8. PreRender 9. (recusive PreRender's for mas...) 10. SaveViewState 11. Render 12. (recusive Render's for mas...) 13. Unload
...and from what I can gather, if dependent of the state of user controls placed in a masterpage, I should put the code in prerender as you said. How come all beginner tutorials are so focused on Page_Load then?matsnas wrote:
How come all beginner tutorials are so focused on Page_Load then?
Because the stupid IDE generates page load and not page prerender methods. The most important thing to understand is that all events happen after load and before prerender, that's another reason that all rendering steps should take place in prerender, so they reflect the results of any events.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )