Dock close postback event not firing in 2009 Q2

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

    Posted 26 Jan 2010 Link to this post


    Having a problem when closing docks where the serverside postback method is not being called.

    The docks are dynamically created using the page_init method and have a DockCommand added which is used to close the dock. When clicking the command button the user is prompted using javascript to confirm that they want to remove the dock. The dock is removed from the screen but the serverside postback method is not called. This method is used to persist the dock removal in session and database.

    Serverside code for adding dock command
    Dim closeDock As New DockCommand() 
    closeDock.OnClientCommand = "PromptRemoveDock" 
    closeDock.AutoPostBack = True 
    closeDock.Name = "Close" 
    closeDock.Text = "Remove" 
    closeDock.CssClass = "DockCloseCommand" 
    dock.CommandsAutoPostBack = True 
    AddHandler dock.Command, AddressOf Dock_Command 

    Javascript to prompt user before closing dock
    function PromptRemoveDock(sender, eventArgs) 
        if (confirm('Remove "' + sender.get_title() + '"?'))      

    This was working but decided to mysteriously stop behaving. Any ideas as to why would be greatly appreciated. A serverside event for the PositionChanged command is being called via postback with no problems.

    To fix this I did try changing the dock creating to use the DockCloseCommand instead of the DockCommand. This presented a different problem where the dock is removed from the screen before the javascript prompt is displayed. This is not desired, especially when the user click cancel when they don't want to remove the dock.

    Alternate code tried for adding dock command
    Dim closeCommand As DockCloseCommand 
    closeCommand = New DockCloseCommand 
    closeCommand.AutoPostBack = True 
    closeCommand.OnClientCommand = "PromptRemoveDock" 
    AddHandler dock.Command, AddressOf Dock_Command 

    We're using version the 2009 Q2 release (version 2009.2.826.20) of the controls in which I believe the animation bug that can cause this behaviour was fixed.

  2. Answer
    Pero avatar
    1156 posts

    Posted 29 Jan 2010 Link to this post

    Hello Brad,

    You should use different Name for the custom DockCommand that serves as Close Command, because there might be a JavaScript error when using any of the predefined command names (such as "Close" "ExpandCollapse" "PinUnpin" etc.). I changed closeDock.Name = "Close" to closeDock.Name = "CustomClose" and the problem disappeared. Here is the full source code of the project that I tested:

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head runat="server">
        <script type="text/javascript">
            function PromptRemoveDock(sender, eventArgs)
                if (confirm('Remove "' + sender.get_title() + '"?'))
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Postback" />
            <telerik:RadDockLayout ID="RadDockLayout1" runat="server">
                <telerik:RadDockZone ID="RadDockZone1" runat="server" Width="300px" MinHeight="300px">
        <asp:Label ID="Label1" runat="server"></asp:Label>

    Imports Telerik.Web.UI
    Partial Class Dock_Close_Command
        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"
            Dim closeDock As New DockCommand()
            closeDock.OnClientCommand = "PromptRemoveDock"
            closeDock.AutoPostBack = True
            closeDock.Name = "CustomClose"
            closeDock.Text = "Remove"
            closeDock.CssClass = "DockCloseCommand"
            Dock.CommandsAutoPostBack = True
            AddHandler Dock.Command, AddressOf Dock_Command
        End Sub
        Protected Sub Dock_Command(ByVal sender As Object, ByVal e As DockCommandEventArgs)
            Label1.Text = DateTime.Now.ToString()
        End Sub
    End Class

    All the best,
    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. DevCraft R3 2016 release webinar banner
  4. brad
    brad avatar
    11 posts
    Member since:
    Apr 2008

    Posted 31 Jan 2010 Link to this post

    Thank you. It was as something as simple as that.

  5. HL
    HL avatar
    55 posts
    Member since:
    Dec 2009

    Posted 01 Mar 2010 Link to this post

    I tried to use this example on my project but I got the index outof bound error on line :
    'RadDockZone1.Controls.Add(dock)   ( inside CreateDefaultRadDock()   function)

     I searched and found the solution from the following link by using
            dock.DockZoneID = "RadDockZone1"; 
    After i used these two line codes, I didn't get the index outof bound error but the dock didn't add the correct RadDockZone.
    Any idea ? Also How can I apply the image when i create the Dock Command? I didn't find any property to allow you to apply the image for DockCommand. I am using 2009.3.1314.35 version. I just still want default close command image icon with adding my own jabascript

    What I need do:
        When user close the Dock, It needs to call some javascript first to uncheck Checkboxlist item before Dock has been closed

    My codes:
      Private Function CreateRadDock(ByVal strTitle As String) As RadDock  
            Dim dock As New RadDock()  
            dock.DockMode = DockMode.Docked  
            dock.UniqueName = Guid.NewGuid().ToString()  
            dock.ID = String.Format("RadDock{0}", dock.UniqueName)  
            dock.Title = strTitle 
            dock.EnableAnimation = True 
            dock.Text = String.Format("Added at {0}", DateTime.Now)  
            dock.Width = Unit.Percentage(95)  
            dock.BorderWidth = Unit.Pixel(2)  
            dock.BorderColor = Color.LightGray  
            dock.OnClientDragStart = "OnClientDragStart" 
            dock.OnClientDragEnd = "OnClientDragEnd" 
            Dim closeDock As New DockCommand()  
            closeDock.OnClientCommand = "ChangeCheckBoxList" 
            closeDock.AutoPostBack = True 
            closeDock.Name = "CustomClose" 
            closeDock.Text = "Remove" 
            closeDock.CssClass = "DockCloseCommand" 
            dock.CommandsAutoPostBack = True 
            'dock.Commands.Add(New DockCloseCommand())  
            dock.Commands.Add(New DockExpandCollapseCommand())  
            Return dock  
        End Function  
    'if user doesn't have Docklayout setting yet,it will load all the controls from the checkbox to three radzones  
        Private Sub CreateDefaultRadDock()  
            Dim index As Integer  
            Dim DockList As New ArrayList()  
            Dim intCount As Integer = 0 
            Dim intReminder As Integer  
            Dim dock As RadDock  
            If Not Me.chkDockList.Items Is Nothing Then  
                intCount = Me.chkDockList.Items.Count  
            End If  
            For index = 0 To intCount - 1  
                dock = CreateRadDock(chkDockList.Items(index).Text)  
                intReminder = index Mod 3  
                Select Case intReminder  
                    Case 0  
                        dock.DockZoneID = "RadDockZone1" 
                    Case 1  
                        dock.DockZoneID = "RadDockZone2" 
                    Case 2  
                        ' RadDockZone3.Controls.Add(dock)  
                        dock.DockZoneID = "RadDockZone3" 
                End Select  
                Me.chkDockList.Items(index).Selected = True 
                ''We want to save the dock state every time a dock is moved.  
                'Load the selected widget  
                dock.Tag = chkDockList.Items(index).Value  
            Next index  
        End Sub 
  6. HL
    HL avatar
    55 posts
    Member since:
    Dec 2009

    Posted 01 Mar 2010 Link to this post

    I found the error why index is out of bound. By mistake, I added all the new docks to RadDockZone1

    I still need help to figure out how can I apply the image to the new command? Now after created this new Dockcommand and attached to the Dock. the close command icon is the same the "DockExpandCollapseCommand" icon

  7. Pero
    Pero avatar
    1156 posts

    Posted 02 Mar 2010 Link to this post

    Hello HL,

    In the DockCloseCommand CSS class that you have applied to the custom command you should specify a new background-image for the custom command. Do not forget the !important flag as the image will not be applied. Please note that the icon should be 19x19. For your convenience I have created a sample project that applies custom image to a custom dock command. It is attached to the thread.

    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.
Back to Top
DevCraft R3 2016 release webinar banner