I have an asp.net web page with a ton of code that is handled in the Page-Load event of the page. I also have a dropdown box on the page that should reload the page with a new value, but I would like to get this new value before I process the entire Page-Load code. I am trying to get my head around ASP.NET page lifecycle.
Should I move the Page-Load code to a later event or is there a way to get the value of the dropdown list value before the the Page-Load event begins?
TIA
The content page load event will fire before the master page load event. Copying incase link goes dead: The following is the sequence in which events occur when a master page is merged with a content page: Content page PreInit event.
Note that the Page_Init event fires only the first time the page is loaded. When you use a web form and post back to this page again, the Page_Init event doesn't fire. But the Page_Load event fires each time the page loads.
The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images. This is in contrast to DOMContentLoaded , which is fired as soon as the page DOM has been loaded, without waiting for resources to finish loading.
Master pages behave like child controls on a page: the master page Init event occurs before the page Init and Load events, and the master page Load event occurs after the page Init and Load events.
I would use Page_PreLoad instead of Page_Init, because it is raised after all postback data is processed.
Try Page_Init
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With