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

How do I capturing events on Dynamicly created docks?

3 Answers 50 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Johnathan
Top achievements
Rank 1
Johnathan asked on 07 Sep 2010, 11:12 AM
Hi

I have a function that creates,populates then returns a RadDoc. This function runs an unknow quantity of times depending on results returns from my db.
This returned dock is then added to a specific dock zone base on data in the database.

ie

 

 

 

 

For Each dashitemrow As Data.DataRowView In dsDashItems.Select(DataSourceSelectArguments.Empty)
  
            Dim dock As RadDock = CreateRadDock(dashitemrow("Itemtype"), dashitemrow("Itemid"))
  
            Select Case dashitemrow("dockindex")
  
                Case 11
                    RadDockZone11.Controls.Add(dock)
                Case 12
                    RadDockZone12.Controls.Add(dock)
                Case 21
                    RadDockZone21.Controls.Add(dock)
            End Select
  
        Next

For varying reason I want to manage the position of the docks myself and not use the dockstate.

My question is, how for these dynamically created contols can I  detect / write the DockpositionChanged event so i can then retrieve the .dockzoneID and .Index and then store them in my database?
I can do this with a statically created dock, but I am not sure how this is implemented dynamically.


I think I need something like:

detect a DockpositionChanged event in a RadDock within the RadDockLayout
    determine which Dock has fired the event
    get this dock's .dockzoneID, .Index and it's DB reference (which I could hide somewhere)
    call my DB_SP with .dockzoneid, .index and id to complete reorder
end event


Thanks

Johnathan

3 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 10 Sep 2010, 09:11 AM
Hello Johnathan,

First of all the dynamically added docks should be re-created on every postback in the Page.Init event. Anytime a dock is created the event  handler method should be attached to the DockPositionChanged event. Basically, you should attach the handler when the dock is created for the first time, and then on every postback in the Page.Init. You can retrieve the DockZoneID and the Index of the dock that fired the event through the event arguments object. Here is a simple page that creates a single dock on every postback in the Page.Init, and handles the DockPositionChanged event:
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form2" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        </Scripts>
    </asp:ScriptManager>
    <asp:Label ID="Label1" runat="server"></asp:Label>
    <div>
        <telerik:RadDockLayout ID="RadDockLayout1" runat="server">
            <telerik:RadDockZone ID="RadDockZone1" runat="server" MinHeight="300px" Width="300px">
            </telerik:RadDockZone>
        </telerik:RadDockLayout>
    </div>
    </form>
</body>
</html>

Imports Telerik.Web.UI
 
Partial Class AttachEvents
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
        Dim dock As New RadDock
        dock.ID = "RadDock1"
        dock.AutoPostBack = True
 
        AddHandler dock.DockPositionChanged, AddressOf Me.DockPositionChanged
        RadDockZone1.Controls.Add(dock)
    End Sub
 
    Protected Sub DockPositionChanged(ByVal sender As Object, ByVal e As DockPositionChangedEventArgs)
        Dim dock As RadDock = DirectCast(sender, RadDock)
        Label1.Text = "PositionChanged fired by: " & dock.ID & " at " & DateTime.Now.ToString
        'e.DockZoneID
        'e.Index
    End Sub
 
End Class


Kind regards,
Pero
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Johnathan
Top achievements
Rank 1
answered on 10 Sep 2010, 10:25 AM
Hi Pero

Thanks for the reply - thats great.
I previously have been using one of your competitors controls but have recently switched to yours because your documentation and support is simply outstanding - better then anything else I have used by miles. - Thank you.

When this DockPositionChanged is fired  then I can clearly get the moved dockID and new dockzone it has been moved into.
To save me lots of brain hurting sorting in my database it would be useful to interate through every dock in the new dockzone and the old dockzone (if it was moved from one dockzone to another). I can then collect the new indexes of the untouched docks and write them back to my database.
So my question is: on this event  how can I iterate through all the docks in the new dockzone and is it possible to detect the old dockzone (not essential but nice)  so I can update the ordering here?

Thanks

Johnathan
0
Pero
Telerik team
answered on 14 Sep 2010, 11:18 AM
Hello Johnathan,

In this case, I think it would be easier to handle the SaveDockLayout server-side event of the RadDockLayout control, and use the RadDockLayout.GetRegisteredDocksState() method to retrieve a List of the states of all docks on the page. This way you wouldn't have to use a custom approach to collect all the docks in the original zone, or the new zone. You simply check the DockZoneID of the dockState and decide which docks are moved to/from the respective zone, and what is their position in the zone.
This event is fired on every postback to the page, so it is fired on every movement of the RadDock.

Sincerely yours,
Pero
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Dock
Asked by
Johnathan
Top achievements
Rank 1
Answers by
Pero
Telerik team
Johnathan
Top achievements
Rank 1
Share this question
or