By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Page lifecycle and dynamic controls

P: n/a
Hi,

Is there good information about the asp.net page lifecycle in
combination with dynamically loaded controls? Or on "how to build
dynamic controls"? I keep hitting problems where values are not
available at the moment I need them.

Current problem:
In a dynamically loaded ascx there is a dropdown. Based on the selected
value (reloading an existing value or responding to a
SelectedIndexChanged event), I create a set of "property edit"
controls. But when I try to save all selected values, the dropdowns in
there (my dropdowns, based on existing dropdowns) sometimes come up
empty.
This happens especially the first time, so when the property controls
are built following a SelectedIndexChanged.

Any suggestions?

Hans Kesting
Nov 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Hans Kesting" <ne*********@spamgourmet.coma écrit dans le message de
news: ut**************@TK2MSFTNGP02.phx.gbl...
Hi,

Is there good information about the asp.net page lifecycle in combination
with dynamically loaded controls? Or on "how to build dynamic controls"? I
keep hitting problems where values are not available at the moment I need
them.

Current problem:
In a dynamically loaded ascx there is a dropdown. Based on the selected
value (reloading an existing value or responding to a SelectedIndexChanged
event), I create a set of "property edit" controls. But when I try to save
all selected values, the dropdowns in there (my dropdowns, based on
existing dropdowns) sometimes come up empty.
This happens especially the first time, so when the property controls are
built following a SelectedIndexChanged.

Any suggestions?

Hans Kesting
I don't know about you particular problem but you have to recreate everytime
your dynamic controls in your Page Init function. Still in the init function
you can set you control's content the first time the page loads
(!IsPostBack).

Subsequent page loads, the viewstate will kicks in but still, you have to
re-create you dynamic control every page loads (even on postbacks).

Hope it helps
Nov 3 '08 #2

P: n/a
Mike Gleason jr Couturier was thinking very hard :
"Hans Kesting" <ne*********@spamgourmet.coma écrit dans le message de news:
ut**************@TK2MSFTNGP02.phx.gbl...
>Hi,

Is there good information about the asp.net page lifecycle in combination
with dynamically loaded controls? Or on "how to build dynamic controls"? I
keep hitting problems where values are not available at the moment I need
them.

Current problem:
In a dynamically loaded ascx there is a dropdown. Based on the selected
value (reloading an existing value or responding to a SelectedIndexChanged
event), I create a set of "property edit" controls. But when I try to save
all selected values, the dropdowns in there (my dropdowns, based on
existing dropdowns) sometimes come up empty.
This happens especially the first time, so when the property controls are
built following a SelectedIndexChanged.

Any suggestions?

Hans Kesting

I don't know about you particular problem but you have to recreate everytime
your dynamic controls in your Page Init function. Still in the init function
you can set you control's content the first time the page loads
(!IsPostBack).

Subsequent page loads, the viewstate will kicks in but still, you have to
re-create you dynamic control every page loads (even on postbacks).

Hope it helps
But if I should create everything in Page_Init, how can I respond to an
IndexChanged event, which doesn't happen until *after* Page_Load?
I know I should rebuild the controls every time. One of my problems is
that I the information I need to decide *what* to (re)build isn't
available yet at the time I should do it.

And an additional question: does Ajax change that lifecycle? (the
pulldown and the properties section ar in an UpdatePanel).

Hans Kesting
Nov 3 '08 #3

P: n/a

"Hans Kesting" <ne*********@spamgourmet.coma écrit dans le message de
news: %2****************@TK2MSFTNGP02.phx.gbl...
Mike Gleason jr Couturier was thinking very hard :
>"Hans Kesting" <ne*********@spamgourmet.coma écrit dans le message de
news: ut**************@TK2MSFTNGP02.phx.gbl...
>>Hi,

Is there good information about the asp.net page lifecycle in
combination with dynamically loaded controls? Or on "how to build
dynamic controls"? I keep hitting problems where values are not
available at the moment I need them.

Current problem:
In a dynamically loaded ascx there is a dropdown. Based on the selected
value (reloading an existing value or responding to a
SelectedIndexChanged event), I create a set of "property edit" controls.
But when I try to save all selected values, the dropdowns in there (my
dropdowns, based on existing dropdowns) sometimes come up empty.
This happens especially the first time, so when the property controls
are built following a SelectedIndexChanged.

Any suggestions?

Hans Kesting

I don't know about you particular problem but you have to recreate
everytime your dynamic controls in your Page Init function. Still in the
init function you can set you control's content the first time the page
loads (!IsPostBack).

Subsequent page loads, the viewstate will kicks in but still, you have to
re-create you dynamic control every page loads (even on postbacks).

Hope it helps

But if I should create everything in Page_Init, how can I respond to an
IndexChanged event, which doesn't happen until *after* Page_Load?
I know I should rebuild the controls every time. One of my problems is
that I the information I need to decide *what* to (re)build isn't
available yet at the time I should do it.

And an additional question: does Ajax change that lifecycle? (the pulldown
and the properties section ar in an UpdatePanel).

Hans Kesting

I see.. for the event part you can (after creating it dynamically):

MyDynamicControl.OnIndexChanged += new [Handler]

Mike
Nov 3 '08 #4

P: n/a
Mike Gleason jr Couturier presented the following explanation :
"Hans Kesting" <ne*********@spamgourmet.coma écrit dans le message de news:
%2****************@TK2MSFTNGP02.phx.gbl...
>Mike Gleason jr Couturier was thinking very hard :
>>"Hans Kesting" <ne*********@spamgourmet.coma écrit dans le message de
news: ut**************@TK2MSFTNGP02.phx.gbl...
Hi,

Is there good information about the asp.net page lifecycle in combination
with dynamically loaded controls? Or on "how to build dynamic controls"?
I keep hitting problems where values are not available at the moment I
need them.

Current problem:
In a dynamically loaded ascx there is a dropdown. Based on the selected
value (reloading an existing value or responding to a
SelectedIndexChanged event), I create a set of "property edit" controls.
But when I try to save all selected values, the dropdowns in there (my
dropdowns, based on existing dropdowns) sometimes come up empty.
This happens especially the first time, so when the property controls are
built following a SelectedIndexChanged.

Any suggestions?

Hans Kesting
I don't know about you particular problem but you have to recreate
everytime your dynamic controls in your Page Init function. Still in the
init function you can set you control's content the first time the page
loads (!IsPostBack).

Subsequent page loads, the viewstate will kicks in but still, you have to
re-create you dynamic control every page loads (even on postbacks).

Hope it helps

But if I should create everything in Page_Init, how can I respond to an
IndexChanged event, which doesn't happen until *after* Page_Load?
I know I should rebuild the controls every time. One of my problems is that
I the information I need to decide *what* to (re)build isn't available yet
at the time I should do it.

And an additional question: does Ajax change that lifecycle? (the pulldown
and the properties section ar in an UpdatePanel).

Hans Kesting


I see.. for the event part you can (after creating it dynamically):

MyDynamicControl.OnIndexChanged += new [Handler]

Mike
I know. The event does fire, my handler gets executed and adds the
'property' fields to the page, so the page looks OK. However when I
then hit the "save" button (after selecting values in the dropdowns of
some properties) those values are lost.
When I revisit the item, the dropdown is filled before the Load and the
property-section is created in the Load event. Now the values in the
property-pulldowns are saved correctly.

So how can I get the property-section to behave correctly after an
"index changed"?
Hans Kesting
Nov 3 '08 #5

P: n/a
Maybe Instead of adding dynamic controls in the event handler (selected
index changed), you can create your dynamic controls in the page Init
function when the selected index is discovered:

You can check if the selected index changed by looking at those in you page
Init:

HttpContext.Current.Request.Form["__EVENTTARGET"]
HttpContext.Current.Request.Form["__EVENTARGUMENT"]

Mike

Nov 3 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.