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

Dock order changed

10 Answers 139 Views
Dock
This is a migrated thread and some comments may be shown as answers.
HL
Top achievements
Rank 1
HL asked on 04 Nov 2011, 10:29 PM
Hi all:
   I use dockzone to load docks in. each dock is user control. I have a dropdownlist which user select and then it will load the existing dockstates

the issue now is that the dock order mess up after I switch dropdownlist  selection. example: for dropdownlist, it has value "a" and value "b". when I select value "A", it will load dockstate1 and then when I select value "b", it will load dockstate2 from database. now I select  value "A"  and the dockstate1 is loaded and docks are ordered correctly. then I change some dock's postion by drag and drop. every thing works fine and dock index saved to database with correct number. then I select value "b" so dockstate2 is loaded. Then  I reselect value  "a", the dockstate1 is reloaded from database with correct index but the dock orders are changed. they order with the Alphbetic instead of the previous order. I found the dock/state index  value changed after   RadDockLayout1.GetRegisteredDocksState()  is called. why the dock index change ? Please see rough codes

any suggestion?

Thanks
Helena
Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs) Handles RadDockLayout1.LoadDockLayout
        'Populate the event args with the state information. The RadDockLayout control
        ' will automatically move the docks according that information.
        'If isNeedReload Then
        Dim state As DockState
        Dim intIndex As Integer
  
            Dim serializer As Script.Serialization.JavaScriptSerializer = New Script.Serialization.JavaScriptSerializer()
            Dim stateList As List(Of DockState) = Me.RadDockLayout1.GetRegisteredDocksState()
              If Not stateList Is Nothing Then
                For Each state In stateList
                     e.Positions(state.UniqueName) = state.DockZoneID
                    e.Indices(state.UniqueName) = state.Index
                Next
            End If
        End If
    End Sub
  
  
  
  
Protected Sub RadDockLayout1_SaveDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs) Handles RadDockLayout1.SaveDockLayout
        Dim strMethodName As String = Me.strClassName & "RadDockLayout1_SaveDockLayout"
        Try
  
     Dim stateList As List(Of DockState) = Me.RadDockLayout1.GetRegisteredDocksState()
                
//on stateList , the dock index changed ????
  
End sub              
  
  
    Protected Sub RadComBoxView_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComBoxView.SelectedIndexChanged
        Dim strMethodName As String = Me.strClassName & "RadComBoxView_SelectedIndexChanged"
        Try
  
            If Not Me.RadComBoxView.SelectedItem Is Nothing Then
  
                'reset SystemUserWidgetID
                SystemUserWidgetID = -1
                Me.CurrentViewTypeID = Me.RadComBoxView.SelectedItem.Value
  
                'need to load WidgetState based on viewid
                Me.GetUserWidgetState()
               CreateWidgetStates()
  
End if                         
           End Sub
 

10 Answers, 1 is accepted

Sort by
0
HL
Top achievements
Rank 1
answered on 08 Nov 2011, 10:55 PM
Can Telerik supportors help this issue ?

Thanks
Helena
0
Slav
Telerik team
answered on 09 Nov 2011, 02:16 PM
Hello Helena,

Since the order of RadDocks is not persisted correctly, most probably the layout of the dock controls is not saved or there are problems with loading it. I am willing to help you, but I will need a fully runnable project in order to inspect how the docks are created and added on the page, how is their layout saved and then loaded. I can suggest checking the online demo My Portal as it is a good example of loading RadDocks dynamically and saving their state.

Please note that currently I am mostly guessing as to what your setup is. If the encountered issue persist, please prepare and send a sample, runnable project that isolates the problem at hand so that we can examine it locally and suggest an appropriate solution.

Greetings,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
HL
Top achievements
Rank 1
answered on 13 Nov 2011, 07:01 AM

Hi Slav:

  Thanks for your information. the link for submit solution doesn't work .Can I exmplain my code and logical instead of building runable project? I use SQL2000 and can't create MDF

 

Basically I can't load dock from widgetstate on page Init event. the reason is that I need to get data from other events which is fired after page_init then I can load dock after the event fired.

so the process is:

1. on page init, no load for dock
2.on Radcombox select index to load widgetstate from the database based on what I selected from Radcombox
3.after I load widgetstate from the database then I create dock from this widgetstate
4. then RadDockLayout1_LoadDockLayout event fire
5. then RadDockLayout1_SaveDockLayout event fired. actually  I shouldn't need call this event since the widgetState is loaded from database and nothing changed

I will copy codes based on this steps. can you please look at to help out my issue?
1.Radcombox select index  event:

 

Protected Sub RadComBoxView_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComBoxView.SelectedIndexChanged
              Try
           If Not Me.RadComBoxView.SelectedItem Is Nothing Then
               'reset SystemUserWidgetID
               SystemUserWidgetID = -1
               Me.CurrentViewTypeID = Me.RadComBoxView.SelectedItem.Value
               'load widgetList based on viewid
               Me.LoadWidgetList(Me.CurrentViewTypeID)
               BindWidgetList()
               'need to load WidgetState based on viewid
               Me.GetUserWidgetState()
               If SystemUserWidgetID <= 0 Then
                   'add default Widget if user has no widgets yet
                   CreateDefaultRadDock()
               Else
                   CreateWidgetStates()
               End If
               Me.reLoadWidgetControlData()
           End If
       Catch AppException As Exception
                  Finally
       End Try
   End Sub

'+---------------------------------------------------------------------------------------------
   '| Method       : GetUserDockState
   '| Purpose      : retrieve user last Dockstate then save it to the session. If user has no dockstate
   '|                then load all the controls which belong to user's defauult dockviewtype
   '| Parameters   : None
   '| Returns      : None
   '+---------------------------------------------------------------------------------------------
   Private Sub GetUserWidgetState()
       Dim ds As DataSet
       Dim dr As DataRow
       Dim dt As DataTable
       Dim drRow As DataRow
       Dim strDockState As String
       Dim objBS As New NIS.BusinessServices.Widget()
       objBS.SystemUserID = SystemUserID
       Dim strMethodName As String = Me.strClassName & "GetUserWidgetState"
       Try
           If SystemUserWidgetID > 0 Then
               'get user existing WidgetState
               ds = objBS.GetSystemUserWidgetStateByUserWidgetID(SystemUserWidgetID)
           Else
               ds = objBS.GetSystemUserWidgetStateByViewTypeID(Me.CurrentViewTypeID)
               If Not ds Is Nothing AndAlso Not ds.Tables(0) Is Nothing > 0 Then
                   dt = ds.Tables(0)
                   If Not dt Is Nothing AndAlso Not dt.Rows Is Nothing AndAlso dt.Rows.Count > 0 Then
                       SystemUserWidgetID = GS.Null2Zero(ds.Tables(0).Rows(0)("SystemUserWidgetID"))
                   Else
                       SystemUserWidgetID = 0
                   End If
               Else
                   SystemUserWidgetID = 0
               End If
           End If
           CommonMethods.SetFormDataSet(GS.tblSystemUserWidget, ds)
       Catch AppException As Exception
           LogMessage(UserToken(), GS.msgInternalApplicationErrorID, strMethodName, Now, Now, AppException.Message)
       Finally
           CommonMethods.cleanupDataSet(ds)
           CommonMethods.CleanUpObject(objBS)
       End Try
   End Sub
   Private Function CreateRadDockFromState(ByVal state As DockState) As RadDock
       Dim dock As New RadDock()
       dock.DockMode = DockMode.Docked
       Dim strMethodName As String = Me.strClassName & "CreateRadDockFromState"
       Dim strID As String()
       Dim strURLType As String
       Try
           With dock
               '.Skin = "NISCustomSkin"
               .Skin = GetSkinNameByViewTypeiD(Me.CurrentViewTypeID)
               .EnableEmbeddedSkins = True
               .Commands.Clear()
               .DockMode = DockMode.Docked
               .UniqueName = state.UniqueName
               .ID = state.UniqueName
               .Title = state.Tag
               'dock.tag need to be virtual path
               .Tag = state.Tag
               .EnableAnimation = True
               .EnableRoundedCorners = "true"
               .Width = Unit.Percentage(100)
               '.BorderWidth = Unit.Pixel(1)
               'dock.BorderColor = Color.LightGray
               .Text = state.Text
               .AutoPostBack = True
               .ApplyState(state)
               .Visible = Not state.Closed
           End With
           ''set up different CSS for ProgressNote
           If dock.ID = "wucWidgetProgressNote.ascx" Then
               dock.Height = 0
               dock.CssClass = "NotesrdContent"
               dock.OnClientInitialize = "DockInitialize"
           End If
           'check if Dock is belong to any pop up
           dock.Attributes.Add("text", state.Text)
                      'add Close command
           Dim DockCloseCommand As New DockCloseCommand
           'DockCloseCommand.OnClientCommand = "DockCloseCommandClick"
           DockCloseCommand.AutoPostBack = True
           dock.Commands.Add(DockCloseCommand)
           Dim DOckCollapseCommand As New DockExpandCollapseCommand
           DOckCollapseCommand.AutoPostBack = True
           dock.Commands.Add(DOckCollapseCommand)
           'Insert first Custom command --view Detail to the dockable object
           If strURLType <> String.Empty AndAlso (strURLType = "1" Or strURLType = "2") Then
               Dim customCommand As New DockCommand
               With customCommand
                   .Text = "Details"
                   .Name = "Details"
                   .CssClass = "CustomCommandCss"  ' it is for css to use default Dock customcommand image
                   '.CssClass = "CommandClass" 'it is the style sheet to disolay telerik default image for custom command
                   .OnClientCommand = "DockDetailCommandClick"
                   .AutoPostBack = False
               End With
               dock.Commands.Add(customCommand)
           End If
          
       Catch AppException As Exception
                  Finally
       End Try
       Return dock
   End Function

2.
Protected Sub RadDockLayout1_LoadDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs) Handles RadDockLayout1.LoadDockLayout
       'Populate the event args with the state information. The RadDockLayout control
       ' will automatically move the docks according that information.
       'If isNeedReload Then
       Dim state As DockState
       Dim intIndex As Integer
    
       If ExternalPatientID > 0 Then
           If Not RadDockZone3.Docks Is Nothing Then
               intIndex = RadDockZone3.Docks.Count
           End If
           Dim serializer As Script.Serialization.JavaScriptSerializer = New Script.Serialization.JavaScriptSerializer()
           Dim stateList As List(Of DockState) = Me.RadDockLayout1.GetRegisteredDocksState()
           'If Not CurrentWidgetStates Is Nothing Then
           If Not stateList Is Nothing Then
               For Each state In stateList
                   If state.Closed Then
                       state.DockZoneID = "ctlwucWidgets_RadDockZone3"
                       state.Index = intIndex
                   End If
                   e.Positions(state.UniqueName) = state.DockZoneID
                   e.Indices(state.UniqueName) = state.Index
               Next
           End If
       End If
   End Sub
Protected Sub RadDockLayout1_SaveDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs) Handles RadDockLayout1.SaveDockLayout
       Dim strMethodName As String = Me.strClassName & "RadDockLayout1_SaveDockLayout"
       Try
           If ExternalPatientID > 0 Then
               Dim stateList As List(Of DockState) = Me.RadDockLayout1.GetRegisteredDocksState()
               Dim serializedList As New StringBuilder()
               Dim i As Integer = 0
               Dim objWidget As New NIS.BusinessServices.WidgetTrans()
               objWidget.SystemUserID = SystemUserID
               Dim drRow As DataRow
               While i < stateList.Count
                   serializedList.Append(stateList(i).ToString()) 'serializedList.Append(serializer.Serialize(stateList(i)))
                   serializedList.Append("|")
                   System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
               End While
               Dim strWidgetState As String = serializedList.ToString()
               'Save the dockState string into DB      
               'If strWidgetState.Trim() <> String.Empty Then
               objWidget.UserToken = UserToken
               SystemUserWidgetID = objWidget.SaveUserWidget(SystemUserWidgetID, Me.CurrentViewTypeID, strWidgetState)
               'update the lastviewtypeid in order to use when navigate from other pages
               UserProfile("LastViewTypeID") = Me.CurrentViewTypeID
               'update Widget 
               If Not FormData.Tables(GS.tblSystemUserWidget) Is Nothing AndAlso FormData.Tables(GS.tblSystemUserWidget).Rows.Count > 0 Then
                   drRow = FormData.Tables(GS.tblSystemUserWidget).Rows(0)
                   drRow.Item("WidgetStates") = IIf(strWidgetState = String.Empty, DBNull.Value, strWidgetState)
               Else
                   GetUserWidgetState()
               End If
               SetControlData()
               ''set up the docklist
           End If
       Catch AppException As Exception
           LogMessage(UserToken(), GS.msgInternalApplicationErrorID, strMethodName, Now, Now, AppException.Message)
       Finally
       End Try
   End Sub

0
HL
Top achievements
Rank 1
answered on 15 Nov 2011, 11:30 PM
Hi Slav:
  I think I kindly figured out why my dock order issue but I am not sure how to fix it
Basically on my situation, when I change the selection from the RadCombox, I couldn't load dock from the page_init since I need to reload the dockstate from the database on the selectindex change event which is fired after page_init and after the

RadDockLayout1_LoadDockLayout

. so on RadDockLayout1_SaveDockLayout, the state is not correct when I retrieved from RadDockLayout1.GetRegisteredDocksState(). I am still confused why the index changed automatically but I am assuming I need to fire

RadDockLayout1_LoadDockLayout

 after I get the latest state from the database. so the question is that how I can fire

RadDockLayout1_LoadDockLayout manually ? Could you please help out with this issue and I really need to fix it asap


Thanks
Helena

 
0
Slav
Telerik team
answered on 16 Nov 2011, 09:49 AM
Hi Helena,

I will explain the process of persisting the layout of the RadDocks so that you can get better understanding of it and check if there is something incorrect in your implementation:

1. On Page_Init the RadDocks that were present on the page before postback are recreated based on the state saved in the data base.
2. On RadDockLayout_LoadDockLayout the position and the index of every RadDock is recovered from the state, saved in the data base.
3. On RadDockLayout_SaveDockLayout the new state of the RadDocks is taken from the method of the RadDockLayout GetRegisteredDocksState() and it is stored in the data base to be used on a new page load.

Since RadDockLayout_LoadDockLayout is raised always in the correct moment of the page lifecycle, you won't need to fire it manually. Also, I checked the provided code samples and I wasn't able to detect what may be causing the issue. Note that I will need to examine your full code in order to detect the exact cause as the presented parts doesn't create a complete picture of your implementation.

Please find attached a sample project that demonstrates the default setup, utilized in such cases. You can compare it with your actual project and check if there are differences in the implementation. I would suggest trying to modify it so that the problem is reproducible or preparing a sample, runnable project that isolates the problem at hand and sending it to clientservice@telerik.com so that we can examine it locally and provide a more to the point answer.

Regards,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
HL
Top achievements
Rank 1
answered on 16 Nov 2011, 03:52 PM
HI Slav:
  Thanks for your explaination. so my code does have issue. I have to load the widgetstate from the database on the selectindexchange event instead of pate_init. It means I only can get all the state after LoadDockLayout fired since the Radcombox selectedindexchange event fire after page_init and after LoadDockLayout . is any way that I call LoadDockLayout after the selectedindexchange event ? 

Thanks
Helena


0
HL
Top achievements
Rank 1
answered on 16 Nov 2011, 07:29 PM
Hi Slav:
   I tried to copy all the codes from RadCombox selectindexChange event to Page_init. then the Dock order issue is fixed. but as I mentioned, I have to leave code inside RadCombox selectindexChange   in order to get some data informatio. so my issue or solution is : is it possible to do the same function which Load_layout do (the position and the index of every RadDock is recovered from the state, saved in the data base.) ouotside page_init?

Thanks
Helena
0
Slav
Telerik team
answered on 17 Nov 2011, 03:15 PM
Hi Helena,

Thank you for the sample and the description of your implementation. After examining your code I have several suggestions for improving your project:

1. For setting the index and position of the RadDocks outside the event LoadDockLayout you can use the method SetRegisteredDockParents of RadDockLayout, which is demonstrated in the online demo Dock / Load/Save Layout.
2. I would recommend separating the logic for recreating the RadDocks in the according events - you can load the controls on Init and populate them with additional information on SelectedIndexChanged of the RadComboBox control.
3. I noticed that in the handler of the server-side event LoadDockLayout you are using the state, returned from the GetRegisteredDocksState method of the RadDockLayout.
Dim stateList As List(Of DockState) = Me.RadDockLayout1.GetRegisteredDocksState()

This is incorrect, as for setting the correct position and index of the recreated RadDocks you should utilize the data, stored in the data base.

I hope the information listed above will help you in resolving the issue.

Greetings,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
HL
Top achievements
Rank 1
answered on 17 Nov 2011, 11:15 PM
Hi Slav:
  Thanks for your information.Can you please confirm why the viewstate varibale is missing after I drag and drop the dock? I have to use session instead of viewstate now to keep variable value.but I can't understand why the viewstate will not work when drag and drop
dock ( dock position change). Also can you please tell me how I can tell dock is drag and drop event? example: I can tell if the event is from RadCombox by checking the eventTarget . is any way for me to tell the page refresh because of dock drag and drop. I only need to save dockstate when dock change position or dock close ( by dock command) so want to know how to check
eventTarget = Page.Request.Params.Get("__EVENTTARGET")
If eventTarget.Contains("RadComBoxView") Then
........

Thanks
Helena'

0
Slav
Telerik team
answered on 22 Nov 2011, 03:06 PM
Hello Helena,

Indeed, the variable SystemUserWidgetID which is stored in ViewState is missing after a postback. This happens because you are setting its value on the RadDockLayout's event SaveDockLayout, which is raised after the ViewState of the page and its controls is saved, as you can check in this article. An alternative approach, that you may consider if you want to keep using the SaveDockLayout event for this purpose, is to store the current index of the RadComboBox in a hidden field instead of the ViewState.

If you want to save the state of the RadDock controls only when a dock is dragged or a command is clicked, you can use its server-side events Command and DockPositionChanged in order to set a flag, indicating that the state of the RadDocks should be saved. In the handler of the event SaveDockLayout you will save the state only if this flag is set.

Kind regards,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Dock
Asked by
HL
Top achievements
Rank 1
Answers by
HL
Top achievements
Rank 1
Slav
Telerik team
Share this question
or