Index of DockState not persisting

38 posts, 0 answers
  1. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 12 Sep 2009 Link to this post

    Wow, two years later, and this is still biting me in the ass!

    I've updated my portal to abandon partial-page postbacks in favor of light, direct Ajax calls.  Now the portal doesn't do any postbacks at all.  My reimplementation completely creates the gadgets/docks in Page_PreRender.  Since there is absolutely no postbacks, this should be fine - except for the fact that the index still doesn't get applied.  I tried the LoadDockLayout thing, but since I'm building the docs in PreRender, it didn't apply (there were no docks yet since that's an event handler and PreRender happens later).

    When a change is made to the position/status of the docks, I make an Ajax call passing in all of the docks, and the Ajax routine updates the database.  When the page is loaded next time, the dock states are read from the database. 

    My only solution was to create the gadgets in the order they needed to appear in the zones.

    This was rather annoying, to say the least.  Do people actually get this to work, or do they not worry about the order of the gadgets?
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 15 Sep 2009 Link to this post

    Hi Barry,

    When the RadDocks are created dynamically they have to be recreated in the Page_Init method on every post-back. If you are re-creating them in the Page_Init (you mention that the docks are created in the Page_PreRender, but never mention when in the page lifecycle they are recreated) everything should be working fine and every RadDock should be placed in the respective zone at the respective index (position).

    If you still have problems even if the docks are re-created in the Page_Init method, please send us a running project where this problem can be observed, and we will do our best to provide a working solution.

    Best wishes,
    Pero
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 15 Sep 2009 Link to this post

    Hello Pero,

    I'm actually not doing postbacks, so there should be no issue related to recreating the docks on a postback.

    What I have done is to place the docks on the page during Page_PreRender.  If they are moved around, a light-weight Ajax call updates the database with the dockstates.  Next time the page is loaded (directly, and not via a postback), it uses that information to place the gadgets.  They show up in the proper zones, but they don't show up in the proper order within the zones.  I've done a lot of debugging to make sure the proper values are being preserved and applied, and I can assure you that they are.

    To work around this, I added a column in the docks/gadgets database to store just the index so that I change the sequence in which the docks are actually added to the page by using an Order By clause in the SQL.  This works.

    To clarify via example:

    I have 4 dock zones called DockZone1, DockZone2, DockZone3, and DockZone4.

    I attempt to place docks on the page by selecting them from the database and adding them to their respective zones.  For simplicity, I will only reference gadgets for DockZone1.  If I retrieve gadgets from the database in the following order (showing their name and partial DockState only):

    "Gadget 1", {"DockZoneID":"DockZone1","Index":"0"}
    "Gadget 2", {"DockZoneID":"DockZone1","Index":"2"}
    "Gadget 3", {"DockZoneID":"DockZone1","Index":1"}

    they appear in the correct zone, but in the order: Gadget 1, Gadget 2, Gadget 3.

    My workaround reads the same data from the database and executes the exact same code.  The only change is the order in which the records are read from the database, and hence the sequence in which the gadgets are added to the page.  Now I read in the order:

    "Gadget 1", {"DockZoneID":"DockZone1","Index":"0"}
    "Gadget 3", {"DockZoneID":"DockZone1","Index":1"}
    "Gadget 2", {"DockZoneID":"DockZone1","Index":"2"}

    By doing this, the gadgets are appear in the correct zone and order: Gadget 1, Gadget 3, Gadget 2.

    When I place a gadget on the page, I perform the following tasks in order:

    1. Create a new Dock.
    2. Create a new DockState.
    3. Deserialize the DockState data and store it in the DockState object.
    4. Set Forbidden Zones for the Dock.
    5. Set the Dock Commands.
    6. Add the Dock to the DockLayout Controls collection.
    7. Use ApplyState to apply the DockState to the Dock.
    8. Dock the Dock in the appropriate DockZone.
    9. Set the Index on the Dock directly from the value in the DockState.
    10. Set the DockMode of the Dock to Docked.
    11. Set the Title of the Dock.
    12. Set the UniqueName of the Dock.
    13. Set the ID of the Dock.
    14. Add the User Control that contains my gadget functionality to the Dock's ContentContainer Controls collection.

    If this is done in Page_PreRender, and we're not doing any postbacks, shouldn't the docks appear in the DockZones in the correct order according to the Index?  Again, I've done a lot of debugging to make sure the correct data is being used in the Docks and DockStates.  In fact, when I set the Dock's title, I set it to the DockZone ID and Index.  The values displayed were correct, but the order within the zones were not.

    I have to stress.  There is no postback involved here.

    Thanks.
    --Barry
  5. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 17 Sep 2009 Link to this post

    Hello Barry,

    I understand that you are not doing any postback, but what if the ajax request (call) affects the RadDocks that are placed in a certain AjaxPanel (or an UpdatePanel), then they would not be recreated when the ajax call has finished and practically would not be rendered on the page. So it does not really matter if it is a full page postback or an ajax call if the control is affected by the page update.

    The indices (indexes) and the positions of the RadDocks are applied in the LoadDockLayout event handler, after all of the RadDocks are created and are on the page. You can see that if you comment the code that is executed in the "RadDockLayout1_LoadDockLayout" event handler method (in the attached project), the indexes will not be applied correctly.

    Please test the project and let me know if you have any problems or questions.    

    Sincerely yours,
    Pero
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 17 Sep 2009 Link to this post

    Hello Pero,

    I should have been more clear.  I'm also not using any AjaxPanels or UpdatePanels of any sort.  All Ajax calls are via Javascript calls directly to web services, so there are no partial page postbacks at all.

    Are you saying that if I have a page where the docks are created in Page_PreRender, I cannot expect the index values to be applied at all because they are only applied in the LoadDockLayout event handler?  (That seems to be the case, as that is what I'm observing.)

    If that's the case, then I understand the restriction as unfortunate as it is.  After all, I have a workaround.

    For the benefit of all, the reason I'm doing this as I am is that I have decided to abandon partial page postbacks.  All of my ajax calls are via JavaScript calls to PageMethods and Web Services.  I do this because I benefit from a pretty good performance boost through faster response times and less network traffic.  It comes at the cost of a longer and more complex development time, but I'm up for the challenge.

    Given this, I could create the docks earlier in the page lifecycle (i.e., in Page_Init), but it would take making changes to several layers of inherited objects that I would do only if I really needed to.  As it is, if the page loads in such a way that the portal view isn't visible (such as when the user requests a configuration view), I don't even have to waste the time and resources building the gadgets.

    If you can confirm the answer to my question above, I would appreciate it.

    Thanks.
    --Barry
  7. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 21 Sep 2009 Link to this post

    Hello Barry,

    Yes, the index values are applied in the LoadDockLayout server side event handler method only. This event receives a parameter of type Telerik.Web.UI.DockLayoutEventArgs, that contains the Positions and Indices properties through which the index values and the positions of the RadDocks are applied. 

    Please note that this is so, because the RadDock's should be (re)created dynamically in the OnInit method so that the server side events (like [On]Command, [On]DockPositionChanged) are fired correctly and the ViewState of the RadDock's is loaded and persisted properly.  

    Best wishes,
    Pero
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 21 Sep 2009 Link to this post

    Thank you.

    That does make perfect sense. 

    I guess I'll stick to my current workaround only because I don't have all of the information available early enough in the page lifecycle.  I'll probably eventually address that, especially if something comes along and forces my hand.  For now, I'm content with the workaround.

  9. Rob Linxweiler
    Rob Linxweiler avatar
    5 posts
    Member since:
    Oct 2009

    Posted 03 Nov 2009 Link to this post

    I'm still working through this.  I've modularized the code, so that docks are created in a method that takes a dockstate as an argument.  Since we're not adding the docks to a layout/zone later, applying the index when the dock is created is not working.

    My workaround for now is to load the dockstates to a list, then sort the list by dockzone and index.  When the docks get re-created, they end up in the right order on the page.


Back to Top
UI for ASP.NET Ajax is Ready for VS 2017