Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Why is this.Page NOT initialized when a composite control's CreateChildControls is being executed

Reply
Thread Tools

Why is this.Page NOT initialized when a composite control's CreateChildControls is being executed

 
 
~~~ .NET Ed ~~~
Guest
Posts: n/a
 
      04-01-2005
That is exactly what I have noticed, my web custom (composite) control gets
instantiated and initialized on the page, so I see that
CreateChildControls() is called as I am debugging it. What I find strange is
that I see that while within CreateChildControls() the "this.Page" property
is undefined!

That gives me a few problems, namely that I cannot determine if I am in a
PostBack or not, if I use this.Page.IsPostBack I get an "object reference
not initialized". Or is there a way for a composite control to determine if
it is being posted back? Anyway, concerning this particular item, I don't
see the logic of having Page undefined, after all the parent page object
exists and is actually creating its child controls (including the composite
control). You can't have the chic without the chicken, or am I missing
something out of this world?

Emil


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      04-04-2005
Hi,

Can you determine at which exact stage your CreateChildControls gets called?
(Tracing can help) Page property is set to a Control at Init stage of the
lifecycle, and if CreateChildControls runs before that, answer is the null
reference as you see.

One design reason being here is that child controls should get added in
CreateChildControls despite it being a postback or not, and the needs what
to accomplish is it a postback or not, is done elsewhere/with different
means. For example with databound controls CreateChildControls does what is
needed when control renders itself from a ViewState without a datasource
(actual control creation is done in DataBind method, when controls are
created from datasource and certain view state data is set).

Can you tell what youi are trying to do with the Page from the control?
Perhaps registering a script block?

--
Teemu Keiski
ASP.NET MVP, Finland

"~~~ .NET Ed ~~~" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> That is exactly what I have noticed, my web custom (composite) control
> gets instantiated and initialized on the page, so I see that
> CreateChildControls() is called as I am debugging it. What I find strange
> is that I see that while within CreateChildControls() the "this.Page"
> property is undefined!
>
> That gives me a few problems, namely that I cannot determine if I am in a
> PostBack or not, if I use this.Page.IsPostBack I get an "object reference
> not initialized". Or is there a way for a composite control to determine
> if it is being posted back? Anyway, concerning this particular item, I
> don't see the logic of having Page undefined, after all the parent page
> object exists and is actually creating its child controls (including the
> composite control). You can't have the chic without the chicken, or am I
> missing something out of this world?
>
> Emil
>



 
Reply With Quote
 
 
 
 
~~~ .NET Ed ~~~
Guest
Posts: n/a
 
      04-04-2005
I was simply trying to get the Context.

"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> Can you determine at which exact stage your CreateChildControls gets
> called? (Tracing can help) Page property is set to a Control at Init stage
> of the lifecycle, and if CreateChildControls runs before that, answer is
> the null reference as you see.
>
> One design reason being here is that child controls should get added in
> CreateChildControls despite it being a postback or not, and the needs what
> to accomplish is it a postback or not, is done elsewhere/with different
> means. For example with databound controls CreateChildControls does what
> is needed when control renders itself from a ViewState without a
> datasource (actual control creation is done in DataBind method, when
> controls are created from datasource and certain view state data is set).
>
> Can you tell what youi are trying to do with the Page from the control?
> Perhaps registering a script block?
>
> --
> Teemu Keiski
> ASP.NET MVP, Finland
>
> "~~~ .NET Ed ~~~" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> That is exactly what I have noticed, my web custom (composite) control
>> gets instantiated and initialized on the page, so I see that
>> CreateChildControls() is called as I am debugging it. What I find strange
>> is that I see that while within CreateChildControls() the "this.Page"
>> property is undefined!
>>
>> That gives me a few problems, namely that I cannot determine if I am in a
>> PostBack or not, if I use this.Page.IsPostBack I get an "object reference
>> not initialized". Or is there a way for a composite control to determine
>> if it is being posted back? Anyway, concerning this particular item, I
>> don't see the logic of having Page undefined, after all the parent page
>> object exists and is actually creating its child controls (including the
>> composite control). You can't have the chic without the chicken, or am I
>> missing something out of this world?
>>
>> Emil
>>

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      04-04-2005
Well,

as a bit hack, you could always try like this:

1. Get reference to System.Web.HttpContext.Current.Handler (or just straight
via Control's Context property)
2. Cast the returned IHttpHandler to System.Web.UI.Page and use it

It is ugly as hell, but should work if you need it.

--
Teemu Keiski
ASP.NET MVP, Finland


"~~~ .NET Ed ~~~" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I was simply trying to get the Context.
>
> "Teemu Keiski" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> Can you determine at which exact stage your CreateChildControls gets
>> called? (Tracing can help) Page property is set to a Control at Init
>> stage of the lifecycle, and if CreateChildControls runs before that,
>> answer is the null reference as you see.
>>
>> One design reason being here is that child controls should get added in
>> CreateChildControls despite it being a postback or not, and the needs
>> what to accomplish is it a postback or not, is done elsewhere/with
>> different means. For example with databound controls CreateChildControls
>> does what is needed when control renders itself from a ViewState without
>> a datasource (actual control creation is done in DataBind method, when
>> controls are created from datasource and certain view state data is set).
>>
>> Can you tell what youi are trying to do with the Page from the control?
>> Perhaps registering a script block?
>>
>> --
>> Teemu Keiski
>> ASP.NET MVP, Finland
>>
>> "~~~ .NET Ed ~~~" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> That is exactly what I have noticed, my web custom (composite) control
>>> gets instantiated and initialized on the page, so I see that
>>> CreateChildControls() is called as I am debugging it. What I find
>>> strange is that I see that while within CreateChildControls() the
>>> "this.Page" property is undefined!
>>>
>>> That gives me a few problems, namely that I cannot determine if I am in
>>> a PostBack or not, if I use this.Page.IsPostBack I get an "object
>>> reference not initialized". Or is there a way for a composite control to
>>> determine if it is being posted back? Anyway, concerning this particular
>>> item, I don't see the logic of having Page undefined, after all the
>>> parent page object exists and is actually creating its child controls
>>> (including the composite control). You can't have the chic without the
>>> chicken, or am I missing something out of this world?
>>>
>>> Emil
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why is CreateChildControls called when a dropdownlist (of a composite control) selected index has changed ~~~ .NET Ed ~~~ ASP .Net Building Controls 1 03-25-2005 12:34 AM
CreateChildControls not being called Colin Young ASP .Net Building Controls 8 11-26-2003 03:09 PM
Struts ActionForm set methods not being executed PERCIVAL BRAGG Java 0 10-15-2003 12:58 AM
Capturing Events before CreateChildControls in Composite Control Lucas Tam ASP .Net 1 08-17-2003 05:02 PM



Advertisments