I am having a doubt in page_init, page preinit, load. I need to know when we use this also where we need to call our objects in different stages of our life cycle.
Please let me know how they will process for each events raised
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Page events happen first before user control events. So the pages PageInit event fires, then the all user controls PageInit events fire. The pages PageLoad event fires, then all user controls PageLoad events fire. etc…
Sometimes developers will put initialization of private objects in their user controls PageLoad handler.
A common gotcha then occurs if the pages PageLoad handler calls a user control method which makes use of uninitialized private objects. Since the user controls PageLoad event hasn’t fired yet, those objects are still ‘null’ and an exception is throw (Object not set to instance of Object).
I then typically use the PageInit handler to initialize internal objects within a user control. That way they are not ‘null’ when the public methods that use them are called.
This technique works if you don’t call any user control methods from the pages PageInit handler. In my opinion, you shouldn’t, though. That is not what handling PageInit in the pages code is for. Use the pages PageLoad handler for user control method calls.