Professional Web Applications Themes

Question for Gurus on CreateChildControls - ASP.NET General

I believe that when you instantiate a Control derived custom control that implements the virtual method CreateChildControls(), that that base class constructor in Control calls EnsureChildControls() which will invoke CreateChildControls(). Am I correct?...

  1. #1

    Default Question for Gurus on CreateChildControls

    I believe that when you instantiate a Control derived custom control that
    implements the virtual method CreateChildControls(), that that base class
    constructor in Control calls EnsureChildControls() which will invoke
    CreateChildControls(). Am I correct?


    Alex Guest

  2. #2

    Default Re: Question for Gurus on CreateChildControls

    Could you explain a little further.
    J

    "Alex" <net> wrote in message
    news:phx.gbl... 


    Justin Guest

  3. #3

    Default Re: Question for Gurus on CreateChildControls

    "Alex" <net> wrote in message
    news:phx.gbl... 

    No. This is very incorrect. If this were the case, there would be no need
    for a separate EnsureChildControls, since they would always be there.

    A piece of code calls EnsureChildControls whenever it requires that the
    child controls be present. If nothing else, ASP.NET will call
    EnsureChildControls at the beginning of the PreRender phase.

    A piece of code which is changing things in such a way as to cause a change
    in the set of child controls should set "ChildControlsCreated = false" so
    that the next time that EnsureChildControls is called, CreateChildControls
    will be called.
    --
    John Saunders
    Internet Engineer
    com


    John Guest

  4. #4

    Default Re: Question for Gurus on CreateChildControls

    On [GMT+0100=CET],
    John Saunders <com> thought hard and spewed:
     
    >
    > No. This is very incorrect. If this were the case, there would be no
    > need for a separate EnsureChildControls, since they would always be
    > there.
    >
    > A piece of code calls EnsureChildControls whenever it requires that
    > the child controls be present. If nothing else, ASP.NET will call
    > EnsureChildControls at the beginning of the PreRender phase.
    >
    > A piece of code which is changing things in such a way as to cause a
    > change in the set of child controls should set "ChildControlsCreated
    > = false" so that the next time that EnsureChildControls is called,
    > CreateChildControls will be called.[/ref]

    Please explain me then, why after I create a custom control using
    Type.CreateInstance(), CreateChildControls() is invoked before my
    constructor? Every time. Do you know for sure that Control constructor does
    not invoke EnsureChildControls()?


    Alex Guest

  5. #5

    Default Re: Question for Gurus on CreateChildControls

    "Alex" <net> wrote in message
    news:phx.gbl... 
    > >
    > > No. This is very incorrect. If this were the case, there would be no
    > > need for a separate EnsureChildControls, since they would always be
    > > there.
    > >
    > > A piece of code calls EnsureChildControls whenever it requires that
    > > the child controls be present. If nothing else, ASP.NET will call
    > > EnsureChildControls at the beginning of the PreRender phase.
    > >
    > > A piece of code which is changing things in such a way as to cause a
    > > change in the set of child controls should set "ChildControlsCreated
    > > = false" so that the next time that EnsureChildControls is called,
    > > CreateChildControls will be called.[/ref]
    >
    > Please explain me then, why after I create a custom control using
    > Type.CreateInstance(), CreateChildControls() is invoked before my
    > constructor? Every time. Do you know for sure that Control constructor[/ref]
    does 

    Absolutely.

    But why in the world are you creating controls using Type.CreateInstance???
    That's sufficiently unusual that it might be the cause of your problem.
    --
    John Saunders
    Internet Engineer
    com



    John Guest

  6. #6

    Default Re: Question for Gurus on CreateChildControls

    On [GMT+0100=CET],
    John Saunders <com> thought hard and spewed:
     

    My architecture dictates a single-page(.aspx) with the content area being a
    panel that can contain a different custom control depending on URL query
    string. So I use query string parameters to form type name and use
    Reflection API to create get the type and create instance. This is an
    implementation of the Builder design pattern.


    Alex Guest

  7. #7

    Default Re: Question for Gurus on CreateChildControls

    "Alex" <net> wrote in message
    news:Oh6S1$phx.gbl... 
    >
    > My architecture dictates a single-page(.aspx) with the content area being[/ref]


    Interesting. In a similar situation, I've filled the panel with a calculated
    user control. That allows "designer-type" people to create the content
    visually. The same application also plays URL games so that users don't have
    to see things like query strings.

    I still don't know if the CreateInstance is your problem. As an experiment,
    how about replacing your Type.CreateInstance with "new SomeControl()"? If
    that works, but CreateInstance doesn't, it will tell you something.
    --
    John Saunders
    Internet Engineer
    com



    John Guest

Similar Threads

  1. Replies: 0
    Last Post: November 1st, 10:11 PM
  2. Replies: 1
    Last Post: October 26th, 04:41 PM
  3. Question about methodology for Gurus
    By JR in forum ASP.NET Web Services
    Replies: 3
    Last Post: December 11th, 04:34 AM
  4. Question to all ASP GURUS
    By MFA in forum ASP Components
    Replies: 2
    Last Post: August 15th, 05:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139