I have found that when I have a composite control that uses the
CreateChildControls method, on a regular page load, Page_Load executes before
CreateChildControls, but on a postback it is the reverse. This is causing
logic problems and it really bothers me that this sequence of events fires
inconsistently. Can anyone tell me why this happens and how we might get
around it? 6 3775
You may have to show a simple example that demonstrates the problem. I just
created a simple web control, threw it on a page, and Page_Load happens
before CreateChildControls everytime.
JD
"V" <V@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com... I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes
before CreateChildControls, but on a postback it is the reverse. This is causing logic problems and it really bothers me that this sequence of events fires inconsistently. Can anyone tell me why this happens and how we might get around it?
One thing I forgot and I apologize.
When creating a composite control, and it has properties or methods that
access any contained controls, the method or property should call
EnsureChildControls method before trying to access the contained control.
EnsureChildControls will call the CreateChildControls method, this will
ensure all child controls are created.
So what this means, in one page rendering if you don't access these methods
or properties, CreateChildControls will happen after page load naturally. If
in the next rendering, say you access one of the properties or methods in
the load view state method, your CreateChildControls method will be called
then, before the page load.
What I suggest is you shouldn't rely on page events within the
CreateChildControl method. Your control should probably hook into the page
events itself and process the logic there.
JD
"V" <V@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com... I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes
before CreateChildControls, but on a postback it is the reverse. This is causing logic problems and it really bothers me that this sequence of events fires inconsistently. Can anyone tell me why this happens and how we might get around it?
Hi JD. None of my properties call EnsureChildControls - they don't need to.
The only thing that does call it is Databind and that is only called from
Page_Load. I searched throughout my code to make sure that
EnsureChildControls is not called from anywhere else. Also, from what you
would describe, it seems that CCC would execute before Page_Load in all
circumstances, not just postback. What I am experiencing only happens
through PostBack. We don't override any postback events either. Lastly,
when I put a breakpoint in to the CCC method, the call stack shows that
ASP.NET called CCC, not any explicit code.
Does anyone know why this would be happening on PostBacks only?
TIA
-Vanessa
P.S. I apologize for the multiple original posts - the MS web page
specifically said my first few posts faild - apparently they did not.
"JD" wrote: One thing I forgot and I apologize.
When creating a composite control, and it has properties or methods that access any contained controls, the method or property should call EnsureChildControls method before trying to access the contained control. EnsureChildControls will call the CreateChildControls method, this will ensure all child controls are created.
So what this means, in one page rendering if you don't access these methods or properties, CreateChildControls will happen after page load naturally. If in the next rendering, say you access one of the properties or methods in the load view state method, your CreateChildControls method will be called then, before the page load.
What I suggest is you shouldn't rely on page events within the CreateChildControl method. Your control should probably hook into the page events itself and process the logic there.
JD "V" <V@discussions.microsoft.com> wrote in message news:B1**********************************@microsof t.com... I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes before CreateChildControls, but on a postback it is the reverse. This is causing logic problems and it really bothers me that this sequence of events fires inconsistently. Can anyone tell me why this happens and how we might get around it?
> EnsureChildControls is not called from anywhere else. Also, from what you would describe, it seems that CCC would execute before Page_Load in all circumstances, not just postback.
There are different events and methods called when a postback happens versus
a non-postback. LoadViewState for example happens only on a postback. What
may be happening is ASP.NET is restoring your control's state which may call
ensurechildcontrols. But I can't say unless I see a simplified example of
where this is happening.
But anyway my suggestion still stand, since you don't know when CCC is going
to be called, you shouldn't be relying CCC to happen in a specific part of
the page lifecycle. Your control should be hooking into the page events
itself.
JD
"V" <V@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com... Hi JD. None of my properties call EnsureChildControls - they don't need
to. The only thing that does call it is Databind and that is only called from Page_Load. I searched throughout my code to make sure that EnsureChildControls is not called from anywhere else. Also, from what you would describe, it seems that CCC would execute before Page_Load in all circumstances, not just postback. What I am experiencing only happens through PostBack. We don't override any postback events either. Lastly, when I put a breakpoint in to the CCC method, the call stack shows that ASP.NET called CCC, not any explicit code.
Does anyone know why this would be happening on PostBacks only?
TIA -Vanessa
P.S. I apologize for the multiple original posts - the MS web page specifically said my first few posts faild - apparently they did not.
"JD" wrote:
One thing I forgot and I apologize.
When creating a composite control, and it has properties or methods that access any contained controls, the method or property should call EnsureChildControls method before trying to access the contained
control. EnsureChildControls will call the CreateChildControls method, this will ensure all child controls are created.
So what this means, in one page rendering if you don't access these
methods or properties, CreateChildControls will happen after page load
naturally. If in the next rendering, say you access one of the properties or methods
in the load view state method, your CreateChildControls method will be
called then, before the page load.
What I suggest is you shouldn't rely on page events within the CreateChildControl method. Your control should probably hook into the
page events itself and process the logic there.
JD "V" <V@discussions.microsoft.com> wrote in message news:B1**********************************@microsof t.com... I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes before CreateChildControls, but on a postback it is the reverse. This is
causing logic problems and it really bothers me that this sequence of events
fires inconsistently. Can anyone tell me why this happens and how we might
get around it?
OK, doing a little more research.
EnsureChildControls is a method of the Control class. It does a virtual call
to CreateChildControls. You override CreateChildControls, which means when
EnsureChildControls calls CreateChildControls, its your method that gets
called.
I did a look to see who in the System.Web.dll calls EnsureChildControls.
There where two that look interesting:
PreRenderRecursiveInternal method of the Control class. Most likely
called at prerender that happens after the page load.
FindControl method of the Control class. Some methods who use this are
ProcessPostData and RaisePostBackEvent methods of the Page class.
The one that looks interesting here is ProcessPostData. What this method
does is go through looking for controls using FindControl, which of course
calls EnsureChildControls, and checks for controls that implement
IPostBackDataHandler interface and calls on this interface the method
LoadPostData. LoadPostData, in the page lifecycle, gets called during the
Load Postback Data phase which is before page load, and only happens on
postback. This is documented.
If I had to guess this is the guy. But I'm guessing since you did not
provide a sample or the callstack output. Tomorrow I may give it a try and
see if I can replicate it.
But again CreateChildControls purpose is to create the contained controls.
Relying on it to happen at a certain time in the page lifecycle is probably
wrong since its not documented in the page lifecycle, and hence can be
called at anytime.
JD
"V" <V@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com... Hi JD. None of my properties call EnsureChildControls - they don't need
to. The only thing that does call it is Databind and that is only called from Page_Load. I searched throughout my code to make sure that EnsureChildControls is not called from anywhere else. Also, from what you would describe, it seems that CCC would execute before Page_Load in all circumstances, not just postback. What I am experiencing only happens through PostBack. We don't override any postback events either. Lastly, when I put a breakpoint in to the CCC method, the call stack shows that ASP.NET called CCC, not any explicit code.
Does anyone know why this would be happening on PostBacks only?
TIA -Vanessa
P.S. I apologize for the multiple original posts - the MS web page specifically said my first few posts faild - apparently they did not.
"JD" wrote:
One thing I forgot and I apologize.
When creating a composite control, and it has properties or methods that access any contained controls, the method or property should call EnsureChildControls method before trying to access the contained
control. EnsureChildControls will call the CreateChildControls method, this will ensure all child controls are created.
So what this means, in one page rendering if you don't access these
methods or properties, CreateChildControls will happen after page load
naturally. If in the next rendering, say you access one of the properties or methods
in the load view state method, your CreateChildControls method will be
called then, before the page load.
What I suggest is you shouldn't rely on page events within the CreateChildControl method. Your control should probably hook into the
page events itself and process the logic there.
JD "V" <V@discussions.microsoft.com> wrote in message news:B1**********************************@microsof t.com... I have found that when I have a composite control that uses the CreateChildControls method, on a regular page load, Page_Load executes before CreateChildControls, but on a postback it is the reverse. This is
causing logic problems and it really bothers me that this sequence of events
fires inconsistently. Can anyone tell me why this happens and how we might
get around it?
Yep this is it, at least in my example.
I created a composite control that contained no controls.
CreateChildControls happened always after page load whether post back or
not. I then added a listbox to my composite control, but did not select any
choices, and again CreateChildControls happened always after page load
whether post back or not (note my composite control is the only thing on the
page). But as soon as I selected a choice from the listbox, on postback
only, the CreateChildControls is called before page load in the load post
back data phase of the page lifecycle.
So there you have the why.
JD
"JD" <no@spam.com> wrote in message news:AWSkd.22723$V41.8434@attbi_s52... OK, doing a little more research.
EnsureChildControls is a method of the Control class. It does a virtual
call to CreateChildControls. You override CreateChildControls, which means when EnsureChildControls calls CreateChildControls, its your method that gets called.
I did a look to see who in the System.Web.dll calls EnsureChildControls. There where two that look interesting: PreRenderRecursiveInternal method of the Control class. Most likely called at prerender that happens after the page load. FindControl method of the Control class. Some methods who use this are ProcessPostData and RaisePostBackEvent methods of the Page class.
The one that looks interesting here is ProcessPostData. What this method does is go through looking for controls using FindControl, which of course calls EnsureChildControls, and checks for controls that implement IPostBackDataHandler interface and calls on this interface the method LoadPostData. LoadPostData, in the page lifecycle, gets called during the Load Postback Data phase which is before page load, and only happens on postback. This is documented.
If I had to guess this is the guy. But I'm guessing since you did not provide a sample or the callstack output. Tomorrow I may give it a try and see if I can replicate it.
But again CreateChildControls purpose is to create the contained controls. Relying on it to happen at a certain time in the page lifecycle is
probably wrong since its not documented in the page lifecycle, and hence can be called at anytime.
JD
"V" <V@discussions.microsoft.com> wrote in message news:5C**********************************@microsof t.com... Hi JD. None of my properties call EnsureChildControls - they don't need to. The only thing that does call it is Databind and that is only called
from Page_Load. I searched throughout my code to make sure that EnsureChildControls is not called from anywhere else. Also, from what
you would describe, it seems that CCC would execute before Page_Load in all circumstances, not just postback. What I am experiencing only happens through PostBack. We don't override any postback events either.
Lastly, when I put a breakpoint in to the CCC method, the call stack shows that ASP.NET called CCC, not any explicit code.
Does anyone know why this would be happening on PostBacks only?
TIA -Vanessa
P.S. I apologize for the multiple original posts - the MS web page specifically said my first few posts faild - apparently they did not.
"JD" wrote:
One thing I forgot and I apologize.
When creating a composite control, and it has properties or methods
that access any contained controls, the method or property should call EnsureChildControls method before trying to access the contained control. EnsureChildControls will call the CreateChildControls method, this
will ensure all child controls are created.
So what this means, in one page rendering if you don't access these methods or properties, CreateChildControls will happen after page load naturally. If in the next rendering, say you access one of the properties or methods in the load view state method, your CreateChildControls method will be called then, before the page load.
What I suggest is you shouldn't rely on page events within the CreateChildControl method. Your control should probably hook into the page events itself and process the logic there.
JD "V" <V@discussions.microsoft.com> wrote in message news:B1**********************************@microsof t.com... > I have found that when I have a composite control that uses the > CreateChildControls method, on a regular page load, Page_Load
executes before > CreateChildControls, but on a postback it is the reverse. This is causing > logic problems and it really bothers me that this sequence of events fires > inconsistently. Can anyone tell me why this happens and how we
might get > around it?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sheila Jones |
last post by:
Hello,
I have a couple of textbox controls which each fire TextChanged events.
AutoPostBack is false for both controls, so the events only actually fire
when another control causes a postback....
|
by: Krista Lemieux |
last post by:
I'm new to ASP.NET and I'm not use to the way things are handled with
this technology. I've been told that when I have a control, I should
only bind the data to it once, and not on each post back...
|
by: Chris Thunell |
last post by:
I have created several grids dynamically and have added them to different
HTML placeholders on a vb.net web form. The grids and controls within them
come up and view beautifully when the web page...
|
by: Olivier Matrot |
last post by:
Hello,
This has probably been asked several times, but It must be clarified for me.
I would like to know why sometimes during a postback Page_Load is called
after the function marked for...
|
by: V |
last post by:
I have found that when I have a composite control that uses the
CreateChildControls method, on a regular page load, Page_Load executes before
CreateChildControls, but on a postback it is the...
|
by: Alexander Widera |
last post by:
i have a problem with postback... i don't find an answer ... only the same
problem without a solution....
(look here:...
|
by: brad |
last post by:
Group,
I'm using Visual Studio 2003 to create an ASP.NET 1.1 project which
contains nested server user controls in order to create a tree-like
hierarchy.
The tree is a sort of question and...
|
by: John Kotuby |
last post by:
Hi guys,
I am converting a rather complicated database driven Web application from
classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The
original ASP application works quite...
|
by: slikrik98 |
last post by:
Greetings,
I believe I have narrowed down my issues to one simple question, and I'm hoping someone with async events experience can help me out.
My question is: how is using...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |