DaeMoohn:
I created a public function into the user control that should be called somewhere in the contentplaceholder. That function loads some data in the usercontrol and on the OnLoad of the usercontrol i draw some dynamic controls. The problem that i have is that by calling that public function in the OnPreInit of the contentplaceholder, i get a null pointer exception, the user control doesn't exist, yet.
That is my problem :|
Hi DaeMoohn,
See the following article:
http://www.codeproject.com/useritems/lifecycle.asp,
And see the following paragraphs:
It is important to note that Master Page is treated like a control in the Content Pages.
So if a Page has a Master Page associated with it, then the controls on the page will not be initialized and would be null in this stage. Only after the Init() event starts, you can access these controls directly from the page class. Why?
The reason being that all controls placed in the Content Page are within a ContentPlaceholder which is a child control of a MasterPage. Now Master Page is merged and treated like a control in the Content Pages. As I mentioned earlier, all events except the Init() and Unload() are fired from outermost to the innermost control. So PreInit() in the Page is the first event to fire but User Controls or MasterPage (which is itself a Usercontrol) do not have any PreInit event . Therefore in the Page_PreInit() method, neither the MasterPage nor any user control has been initialized and only the controls inside the Page class are set to their default values. Only after the Page_PreInit() event the Init() events of other controls fire up.
This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
Hope it helps,
Hong Gang