Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Page lifecycle and dynamic controls

Reply
Thread Tools

Page lifecycle and dynamic controls

 
 
Hans Kesting
Guest
Posts: n/a
 
      11-03-2008
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


 
Reply With Quote
 
 
 
 
Mike Gleason jr Couturier
Guest
Posts: n/a
 
      11-03-2008

"Hans Kesting" <(E-Mail Removed)> a écrit dans le message de
news: ut$(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      11-03-2008
Mike Gleason jr Couturier was thinking very hard :
> "Hans Kesting" <(E-Mail Removed)> a écrit dans le message de news:
> ut$(E-Mail Removed)...
>> 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


 
Reply With Quote
 
Mike Gleason jr Couturier
Guest
Posts: n/a
 
      11-03-2008

"Hans Kesting" <(E-Mail Removed)> a écrit dans le message de
news: %(E-Mail Removed)...
> Mike Gleason jr Couturier was thinking very hard :
>> "Hans Kesting" <(E-Mail Removed)> a écrit dans le message de
>> news: ut$(E-Mail Removed)...
>>> 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


 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      11-03-2008
Mike Gleason jr Couturier presented the following explanation :
> "Hans Kesting" <(E-Mail Removed)> a écrit dans le message de news:
> %(E-Mail Removed)...
>> Mike Gleason jr Couturier was thinking very hard :
>>> "Hans Kesting" <(E-Mail Removed)> a écrit dans le message de
>>> news: ut$(E-Mail Removed)...
>>>> 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


 
Reply With Quote
 
Mike Gleason jr Couturier
Guest
Posts: n/a
 
      11-03-2008
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



 
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
User Controls Event Lifecycle Jonny ASP .Net 2 09-14-2005 12:28 AM
Dynamic Controls in User Control; page/control lifecycle question Frankie ASP .Net 2 06-23-2005 04:07 PM
ASP.NET page lifecycle and In-Line code redhair ASP .Net 1 11-30-2004 03:21 PM
help: question about LifeCycle for controls that change the 'shape' of their control tree? Sky ASP .Net Web Controls 7 07-09-2004 10:34 PM
Page and control lifecycle John Lau ASP .Net 2 05-11-2004 10:25 PM



Advertisments