DockPositionChanged event and dynamic docks

7 posts, 2 answers
  1. brad
    brad avatar
    11 posts
    Member since:
    Apr 2008

    Posted 20 May 2008 Link to this post

    I've created a project that saves dockstate to a database and dynamically adds docks to the page (based on the myPortal with db example found in these forums).

    My project contains one page where a user is displayed a number of default docks and others they have added from a second page.

    To reduce the load on the database, instead of saving the dockState to the database every time SaveDockLayout is fired I was planning on retaining the dockState in session and only saving to the database when a dock is actually moved or removed from the database. Part of this I believe can be achieved using the server side event DockPositionChanged. The problem is I cannot get this event to fire.

    When creating the dock i've tried the following:
    dock.Attributes.Add("OnDockPositionChanged""RadDock_DockPositionChanged"
    dock.OnClientDockPositionChanged = "RadDock_DockPositionChanged" 


    The second obviously doesn't work as it is looking for client code.

    Code for the event handler (that doesn't get fired)
    Protected Sub RadDock_DockPositionChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.DockPositionChangedEventArgs) 
        Dim dock As RadDock 
        dock = DirectCast(sender, RadDock) 
     
        If dock.DockZoneID <> e.DockZoneID Then 
    ... 

    How do you wire up the dynamically created dock to fire the server event?

    Thanks.

  2. Sophy
    Admin
    Sophy avatar
    636 posts

    Posted 21 May 2008 Link to this post

    Hi Brad,

    To fire the DockPositionChanged event you should set event handler to the DockPositionChanged event in the following way:
    dock.OnClientDockPositionChanged = "RadDock_DockPositionChanged"
    and make sure that the dock's property AutoPostBack is set to true. Please, note this comment in the Dynamically Created Docks online example:

        Ensure that the RadDock control will initiate postback
        when its position changes on the client
        Using the trigger we will "ajaxify" that postback.

    If you need further assistance, do contact us again.

    Kind regards,
    Sophy
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. brad
    brad avatar
    11 posts
    Member since:
    Apr 2008

    Posted 21 May 2008 Link to this post

    dfjjg

    Thanks for the reply.

    I've tried your suggestion of setting dock.AutoPostBack to true and dock.OnClientPositionChanged

    This doesn't result in the server side event being fired but instead the browser throws an error saying it can't find the procedure. If I add a javascript function with the same name it gets executed when moving a dock around. I was expecting the server side event be fired as part of the postback - should it?

    This is the code I'm using to create the dock and the DockPositionChanged evert.

    Private Function CreateRadDockFromState(ByVal state As DockState) As RadDock  
        Dim dock As New RadDock()  
        dock.ID = String.Format("RadDock{0}", state.UniqueName)  
        dock.DockMode = DockMode.Docked  
        dock.AutoPostBack = True 
        dock.OnClientDockPositionChanged = "RadDock_DockPositionChanged" 
        dock.ApplyState(state)  
        AddHandler dock.Command, AddressOf dock_Command  
        dock.Commands.Add(New DockCloseCommand())  
        dock.Commands.Add(New DockExpandCollapseCommand())  
        Return dock  
    End Function 
     
    Protected Sub RadDock_DockPositionChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.DockPositionChangedEventArgs)  
        Dim dock As RadDock  
        dock = DirectCast(sender, RadDock)  
        If dock.DockZoneID <> e.DockZoneID OrElse dock.Index <> e.Index Then 
            SaveDockStateToDB()  
        End If 
    End Sub 
     


    Any suggestions will be appreciated.

  5. Answer
    Sophy
    Admin
    Sophy avatar
    636 posts

    Posted 22 May 2008 Link to this post

    Hi Brad,

    Please, accept my apologies for having misled you somehow. I will clarify what you need to do.
    If you want to fire the server-side event DockPositionChanged you should add an event handler to the corresponding dock at page init (or at CreateRadDockFromState and CreateRadDock in your case) in the following way:
    dock.DockPositionChanged += new DockPositionChangedEventHandler(RadDock_DockPositionChanged); 
    where the RadDock_DockPositionChanged is the name of the event handler method.
    More details about the DockPositionChanged server event you can find in this help article.
    An event handler to the client event OnClientDockPositionChanged can be added in the previously discussed way, e.g.:
    dock.OnClientDockPositionChanged = "RadDock_DockPositionChanged" 
    where RadDock_DockPositionChanged  is a javascript function.

    Please, let me know in case you still experience any problems.

    Best regards,
    Sophy
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Answer
    brad
    brad avatar
    11 posts
    Member since:
    Apr 2008

    Posted 22 May 2008 Link to this post

    Thanks Sophy.
    That's exactly what I needed. When I read your answer it was obvious, I just hadn't thought of it when trying to work it out.

    For anyone who needs to do this in vb, as I do, the syntax is:
    AddHandler dock.DockPositionChanged, AddressOf RadDock_DockPositionChanged 

  7. Chris
    Chris avatar
    1 posts
    Member since:
    Jul 2012

    Posted 15 May 2012 Link to this post

    I have followed this post and for some reason the DockPositionChanged event does not fire.  My code is below.  Any help would be greatly apprecaited.  thx.

     

     

    Private Function CreateRadDock(ByVal intIndex As Integer) As RadDock
            Dim dock As New RadDock()
     
            dock.DockMode = DockMode.Docked
            dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a")
            dock.ID = String.Format("RadDock{0}", dock.UniqueName)
            dock.Title = "Dock"
            dock.Text = String.Format("Added at {0}", DateTime.Now)
            dock.Width = Unit.Percentage(100)
            dock.AutoPostBack = True
            dock.Index = intIndex
     
     
            dock.Commands.Add(New DockCloseCommand())
            dock.Commands.Add(New DockExpandCollapseCommand())
     
            AddHandler dock.DockPositionChanged, AddressOf RadDock_DockPositionChanged
     
            Return dock
        End Function
     
     
        Protected Sub RadDock_DockPositionChanged(ByVal sender As Object, ByVal e As DockPositionChangedEventArgs)
            Dim dock As RadDock
     
            dock = DirectCast(sender, RadDock)
     
            Response.Write("ZoneId:" & e.DockZoneID & "  Index: " & e.Index)
     
     
        End Sub

     

  8. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 18 May 2012 Link to this post

    Hi Chris,

    Note that when a RadDock control is created dynamically, you should recreate it by using the same ID and UniqueName when the page is reloaded. Please check this help article, as well as the example in the online demo Dock / My Portal in order to ensure that the dock control on your page are created properly.

    Also, the handler of the event DockPositionChanged should be attached every time the RadDocks are recreated on your page.

    If you are still having difficulties after examining the provided information, please send a simple, runnable page that isolates the problem so that I can inspect it locally and suggest a concrete solution.

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017