Page_PreInit User Control NullReferenceException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sergio Scotto
    New Member
    • Nov 2012
    • 2

    Page_PreInit User Control NullReferenceException

    Hi, i am new in the forum ^^

    I have an issue

    I got a webpage that uses a UserControl wich create dynamic controls on him, i need to create the controls on the Page_PreInit event so i can access to them in the postback when the user do a click, but when i am at the PreInit event the UserControl is null so i cant create any control.

    Can someone explain how to do this?

    in my specific case my user control got 2 accordions, and 2 buttons, the idea is moving panes from one acccordion to another, so i created dynamic panes with dynamics controls like, checkbox, textbox, etc and add to the accordion, then user check the checkboxs on the panes, and by clicking pass those panes to the other accordion, the problem i got is that on postback the accordions on the userControl dont have any panes so i need to create them on Page_PreInit to maintain the state.

    Thx!
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Please post the code that you've already worked on; formating it using the <CODE/> button in the toolbar.

    Comment

    • PsychoCoder
      Recognized Expert Contributor
      • Jul 2010
      • 465

      #3
      Have you tried the Page_Init event? Possible in PreInit it;s too early in the page cycle for the control to be actually created and accessible (just a thought)

      Comment

      • Sergio Scotto
        New Member
        • Nov 2012
        • 2

        #4
        It works fine using the Page_Init event instead od Page_PreInit, i dont know why i didn“t try that before post lol xD

        thx for the answers guys!

        Comment

        Working...