I have a custom control that own a property. Inside this custom control OnInit method, it utilities this property to do some other job.
So in page side, I initialize this custom control and set its property in Page_Init method. But the custom control’s Oninit method is called earlier than the Page_Init method, which means I never get the right property value in OnInit method. So what is the right place to set up the custom control’s property value from page code behind side?
Thanks
PreInit exists only for the page, so if you need to set something from the page, that can work. Init fires in reverse order, first for the lowest level control, bubbling up to the page to fire last. All other events fire from the page first on down.
If PreInit can work, use it. Otherwise, another workaround is for the property to check if the value is null and has not provided, and if not, it could fire a NeedValue event requiring you to supply it.
HTH.