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

New Tiles added from Server do not survive PostBack

4 Answers 88 Views
TileList
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 27 Apr 2014, 11:51 PM
I have a page where the user can add new RadTextTiles to a RadTileList dynamically.  This is handled on the server-side by creating a new RadTextTile in memory and adding it like this:

RadTileList1.GetAllTiles.Add(newTile)

On postback these items do not survive - which is becoming problematic.  Is there a setting or something I am missing that will force RadTextTiles created dynamically on the server (not from databind) to survive a postback?  Other Telerik controls that we use do not display this behavior, so not sure if we are doing something wrong here?

The reason this is a problem is because we are also trying to implement the Persistence Framework, to track the Tile sort order the user sets.  Problem is that the Tiles that are added via the .Add command, are not there on postback, so we cannot pickup their position.

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 29 Apr 2014, 10:55 AM

Hello Dan,

I advise that you first examine the following article: http://www.telerik.com/help/aspnet-ajax/tilelist-server-side-programmatic-creation.html. You will see how programmatically created tiles need to be added to the group you wish them in, not to the collection returned from the GetAllTiles() method. This is merely a list, but you cannot add tiles there because it cannot know which group to add them to.

On postbacks - dynamically created controls need to be recreated in order to survive the postback, and tiles are no exception. Thus, you should recreate them in the Page_Init event, or the Page_Load at latest, but I advise using Page_Init. Once the tiles are recreated properly by the developer, they will be present in the collection so you can store their data.


Regards,

Marin Bratanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dan
Top achievements
Rank 1
answered on 29 Apr 2014, 02:03 PM
Thanks for your reply Marin.  I figured out how to remove the tiles.

For others' sake it is either:

RadTileList1.Groups(i).Tiles.RemoveAt()
or RadTileList1.Groups(i).Tiles.Remove()

If I rebuild the tiles in Page_Init - how do I retain their group and index in the group?  It seems I cannot simply recreate them - just like Remove - I have to add them to a group, but that group is not known on the server-side on postback.

Here if the full requirement:

 - Implement RadTileList with some base tiles included in ASPX, others created dynamically in code, based on user selections
 - Allow the user to add/remove dynamic tiles
 - Allow the user to reorganize the tiles (change groups and position)
 - Save the Sort order of all tiles and groups across sessions

I started with the Persistence Framework, but it seems to break when complex things happen between postbacks, for instance when Tiles are removed dynamically, others are moved to different groups, etc (throws JS AJAX errors on postback - trying to assign properties to a null control)

I then decided to write the whole Group/Tile index to a variable in Javascript, before each postback.  After I recreate the tiles server-side, I loop through the tiles, removing and re-inserting each where it is supposed to go.  This works sometimes, but other times it causes the RadTileList to throw Javascript errors - for instance when you move items across groups. 

Perhaps I missed something on the recreation of the controls in page_init?  Can I recreate them and somehow get them back in the RadTileList in a way that will retain their position and group before postback?
0
Marin Bratanov
Telerik team
answered on 02 May 2014, 06:36 AM

Hello Dan,

It is up to the development logic to create the proper tile in the proper place. The RadPersistenceFramework requires that the controls whose settings (note that is stores settings, not controls) it works with has the same state and control tree upon save and load.

Also, it is very likely that there is actually a server error but MS AJAX traps it as a client-side exception, so you can look into disabling AJAX or stepping through the server code to see the real exception.

Thus, what you need to make sure is that:

  • tiles are recreated just like any dynamic control. How to determine the proper group depends on your custom logic. When DragAndDrop is enabled, you must do this in Page_Init. Here is what happens to impose this need:
    1. tiles collections for each group travel from the server to the client. This means that the tiles have a certain order at this point in the server collections.
    2. the user drags tiles around, even between groups. This change is stored by the TileList so it can track which tile went where.
    3. the POST data is loaded between page_init and page_load by ASP, so this is when this information is loaded by the control. It goes through the information from the client, recreates the groups and places the tiles in the new server collections according to the order that comes in from the client. This is why at this point (before Page_Load) the TileList must have the same structure and tile count as it did with the previous postback (when the tiles were sent to the client), otherwise a mismatch will occur and data would not be loaded properly for the tiles.

      Thus, if you disabled drag-and-drop (and you do not have data binding), you should be able to create/remove tiles in Page_load.
  • Your programmatic tiles are recreated properly (and have the same count) before the state is Save()-ed or Load()-ed. This is the essence of making sure the control whose settings you load and save is the same.

If these conditions are met, the control state stored by the persistence framework should be applied properly to the tiles in the TileList.

We will also look into improving this loading of data, so that you can create tiles programmatically in Page_Load, but I cannot provide an ETA on that, because we still cannot confirm if it is even possible. I would advise that you monitor the release notes to see if such a feature is available.

Perhaps you can store the current state that you need to load in the session, or in a database, or a file, depending on your preferences.

If you can confirm these conditions are met and there are still errors, I advise that you post the code you have and explain in detail (or record a video) that shows what you do, so we can look into it.


Regards,

Marin Bratanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dan
Top achievements
Rank 1
answered on 04 May 2014, 12:49 AM
Thank you Marin.

Your explanation was very helpful.  Once I moved the Tile Recreation to Page_Init - as well as some Visible=True/False settings on the Tiles that are build in the ASPX - the rest fell in to place quickly.  I had some strange issues with the Persistence Framework when adding and removing tiles dynamically - so I opted for a custom solution to handle that bit.

Thanks again
Tags
TileList
Asked by
Dan
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Dan
Top achievements
Rank 1
Share this question
or