communication between a content page and a user control

Last post 05-29-2007 1:55 AM by DaeMoohn. 5 replies.

Sort Posts:

  • communication between a content page and a user control

    05-23-2007, 3:34 AM
    • Member
      29 point Member
    • DaeMoohn
    • Member since 05-21-2007, 5:13 PM
    • Posts 21

    I had posted my problems earlier these days, but seems no one read it. I will reshape my question:

    Is there any possibility, in a content page, to load data to the user control that is placed in that content page on the OnPreInit() phase?

    By loading data, I mean calling methods from the user control in the content page.

    It seems to me that this works on normal web pages, but in content page this is not the case.

    I would really appreciate some help. Sad 

  • Re: communication between a content page and a user control

    05-23-2007, 5:00 AM
    • Contributor
      3,084 point Contributor
    • Girijesh
    • Member since 10-27-2005, 12:04 PM
    • India
    • Posts 652

    If you want to communicate with user control, then you have to expose properties for that.

  • Re: communication between a content page and a user control

    05-23-2007, 5:05 AM
    • Member
      29 point Member
    • DaeMoohn
    • Member since 05-21-2007, 5:13 PM
    • Posts 21

    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 :|

  • Re: communication between a content page and a user control

    05-23-2007, 9:19 AM
    • Member
      29 point Member
    • DaeMoohn
    • Member since 05-21-2007, 5:13 PM
    • Posts 21
    or maybe call from the user control a function from the content page...
  • Re: communication between a content page and a user control

    05-28-2007, 10:52 PM
    Answer

    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

     

    Hong-Gang Chen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: communication between a content page and a user control

    05-29-2007, 1:55 AM
    • Member
      29 point Member
    • DaeMoohn
    • Member since 05-21-2007, 5:13 PM
    • Posts 21

    Thank you 

Page 1 of 1 (6 items)