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

DockPositionChanged event and dynamic docks

6 Answers 239 Views
Dock
This is a migrated thread and some comments may be shown as answers.
brad
Top achievements
Rank 1
brad asked on 21 May 2008, 02:19 AM
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.

6 Answers, 1 is accepted

Sort by
0
Sophy
Telerik team
answered on 21 May 2008, 07:25 AM
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
0
brad
Top achievements
Rank 1
answered on 22 May 2008, 02:02 AM
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.

0
Accepted
Sophy
Telerik team
answered on 22 May 2008, 07:37 AM
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
0
Accepted
brad
Top achievements
Rank 1
answered on 22 May 2008, 11:31 PM
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 

0
Chris
Top achievements
Rank 1
answered on 15 May 2012, 04:56 PM
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

 

0
Slav
Telerik team
answered on 18 May 2012, 10:58 AM
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.
Tags
Dock
Asked by
brad
Top achievements
Rank 1
Answers by
Sophy
Telerik team
brad
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Slav
Telerik team
Share this question
or