473,324 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Page lifecycle and dynamic controls

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
5 5002

"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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ole Hanson | last post by:
Hi I am having a number of User Controls (ascx) on my page (aspx). The page is in my scenario only working as a dumb "container "giving life to the Controls, as these are handling my UI-logic...
2
by: Sam | last post by:
I have a custom control (MyTextBox - taken from Microsoft website) that implements the IPostBackDataHandler interface. It is added to the controls collection of a placeholder control during the...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
6
by: Glenn Owens | last post by:
I have an ASP.Net page on which there are serveral static controls (listboxes, radiobuttonlist and textboxes). These controls are used to create criteria from which the code-behind will dynamically...
3
by: malcolm | last post by:
Inside of a Page class, how do I capture the Request object values before the Page_Load event is called of that Page? I have a situation where I have many server controls on a Page that get...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
2
by: Frankie | last post by:
I have a user control into which I insert a bunch of controls dynamically. I have it all working just fine - Everything is there on Postback, etc. I load this user control into a hosting ASPX...
4
by: Jeremy Holt | last post by:
Hi, In a windows.forms application I would BeginInvoke a delegate on the UI thread to collect data from a database. When the call returns to the AsyncCallback, if the Control.InvokeRequired =...
4
by: Rob Meade | last post by:
Hi all, I played with my first bit of AJAX the other week and was pleasantly surprised that I achieved my goal..now I'd like to try something else.. Question... If I have an updatePanel,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.