This is a migrated thread and some comments may be shown as answers.

Persisting Dynamically Generated Controls in an AJAX Environment

3 Answers 72 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 13 Mar 2011, 02:31 AM
I am currently working on an ASP.NET AJAX page that is fairly sophisticated (VS 2010 and .NET 4.0 w/ VB.NET).  After several initial criteria are entered on the page and submitted back to the database via AJAX, I then dynamically create sixteen RAD controls in individual PlaceHolders.  Each control might be a RadTextBox, RadComboBox, RadNumericTextBox or a RadDatePicker - depending on what the database tells me to display.  I have this all working fine - initially.  I collect the initial data, hand it back and then display the dynamic fields - very cool through AJAX.

However this page then continues to make several AJAX round trips after these dynamic controls are generated, and the user can enter or select values in these custom controls at any point between these subsequent round trips.  The user can also change the initial data parameters which will then potentially recreate all new and different custom controls.  The only commonality is that there are 16 of these custom fields....

After much reading it appears that my dynamic controls are not surviving the AJAX postbacks, and must be recreated and reset each time.  I believe I may need to store the Control Type, ID and SelectedValue (or Text, or Date) in the ViewState and reinitialize them on each Page_Load, but I am not sure how to go about this.  Specifically:

1) How do I save the value on each control before an AJAX PostBack?
2) Are there best practices to follow for this type of interaction to optimize performance?
3) Any specific examples of this kind of interaction with the Telerik AJAX controls?

Any help or pointers appreciated.

3 Answers, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 1
answered on 14 Mar 2011, 06:45 PM
Quick follow-up to some of my questions after a couple of days of debugging:

 - Values are held somewhere even when the dynamic controls are destroyed - so all you need to do is reinitialize the controls with the same IDs - the rest will be there.  Seems best to write a little reinitialize widget that you execute on each page load. 
 - To avoid ViewState crashes where I would stuff different control types in a PlaceHolder between AJAX postbacks, I turned the Viewstate off on those Placeholders...  This worked great - except in the case of ListBoxes - where I had to leave the ViewState enabled to pull out the Checked values...

0
Maria Ilieva
Telerik team
answered on 17 Mar 2011, 01:22 PM
Hi Dan,

Excuse our late response.

I'm not completely sure if I correctly understand your scenario and the exact issues you are facing. If the main problem you are facing is the users’ interaction during the Ajax requests I would suggest you to disable the controls on the page during this requests in order to ensure that no changes will be made. Please refer to the following help topic for more information on this matter.
If this is not the exact functionality you need to achieve, please provide some more information on your application and code snippets related to the mentioned problems, so we could be more aware with the exact scenario and do our best to provide proper approach.

Regards,
Maria Ilieva
the Telerik team

0
lakshmi
Top achievements
Rank 1
answered on 12 Apr 2011, 08:02 PM
Hi Dan,
I am working on an app that needs to show the telerik control on browser depending on database procedure.
I couldnt found an example on telerik site. 
I have never created Dynamic controls before, can you please send me a sample code??

Will be thankfull to you. Please help me.
Tags
Ajax
Asked by
Dan
Top achievements
Rank 1
Answers by
Dan
Top achievements
Rank 1
Maria Ilieva
Telerik team
lakshmi
Top achievements
Rank 1
Share this question
or