Thursday, July 30, 2009

How does ASP.Net choose which code from similar subs runs in what order?

Say my ASP.Net page has a Page_Load sub. Say it contains two user controls, both which also have a Page_Load sub. Say it also references a Master Page with a Page_Load sub and extends from another class which also has a Page_Load sub.





When the page executes, how does the runtime decide which Page_Load sub executes first? How does it order all of them? What if the code in one of them depends on the execution of code in another one?

How does ASP.Net choose which code from similar subs runs in what order?
The Page_Load of the page executes first. You should be aware of this. The page life cycle is one of the most misunderstood issues in ASP.NET. That in addition to viewstate.





The Load event is raised for the page first and then recursively for all child controls. At this time, controls in the page tree are created and their state fully reflects both the previous state and any data posted from the client. The page is ready to execute any initialization code that has to do with the logic and behavior of the page. At this time, access to control properties and view state is absolutely safe.





Thank You!
Reply:Page loads first and then the Master Page's load event fires. After this, ASP.NET will then loop through all controls and fire their load event. This is how it's done all the time.





If your code has some type of dependency, you will have to figure out how to handle it. Since I'm not sure what your dependency is, I really can't help you out.


No comments:

Post a Comment