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

Dock close postback event not firing in 2009 Q2

5 Answers 68 Views
Dock
This is a migrated thread and some comments may be shown as answers.
brad
Top achievements
Rank 1
brad asked on 27 Jan 2010, 02:50 AM
Hello,

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 
dock.Commands.Add(closeDock) 
AddHandler dock.Command, AddressOf Dock_Command 
 


Javascript to prompt user before closing dock
function PromptRemoveDock(sender, eventArgs) 
    if (confirm('Remove "' + sender.get_title() + '"?'))      
    {      
        sender.set_closed(true);  
    }      
    else     
    {      
        eventArgs.set_cancel(true);       
    } 

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" 
dock.Commands.Add(closeCommand) 
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.

Thanks,
Brad.

5 Answers, 1 is accepted

Sort by
0
Accepted
Pero
Telerik team
answered on 29 Jan 2010, 03:45 PM
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:

.aspx
<%@ 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 runat="server">
    <title></title>
 
    <script type="text/javascript">
        function PromptRemoveDock(sender, eventArgs)
        {
            if (confirm('Remove "' + sender.get_title() + '"?'))
            {
                sender.set_closed(true);
            }
            else
            {
                eventArgs.set_cancel(true);
            }
        }
    </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Button ID="Button1" runat="server" Text="Postback" />
    <div>
        <telerik:RadDockLayout ID="RadDockLayout1" runat="server">
            <telerik:RadDockZone ID="RadDockZone1" runat="server" Width="300px" MinHeight="300px">
            </telerik:RadDockZone>
        </telerik:RadDockLayout>
    </div>
    <asp:Label ID="Label1" runat="server"></asp:Label>
    </form>
</body>
</html>

.vb
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
        Dock.Commands.Add(closeDock)
        AddHandler Dock.Command, AddressOf Dock_Command
 
        RadDockZone1.Controls.Add(Dock)
 
    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,
Pero
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.
0
brad
Top achievements
Rank 1
answered on 01 Feb 2010, 02:25 AM
Thank you. It was as something as simple as that.

0
HL
Top achievements
Rank 1
answered on 01 Mar 2010, 06:35 PM
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
         RadDockLayout1.Controls.Add(dock);
        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

http://www.telerik.com/community/forums/aspnet-ajax/docking/exception-adding-dynamic-dock-with-enableviewstate-false.aspx

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(closeDock)  
      
        'dock.Commands.Add(New DockCloseCommand())  
        dock.Commands.Add(New DockExpandCollapseCommand())  
 
        RadDockZone1.Controls.Add(dock)  
 
        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  
                   'RadDockZone1.Controls.Add(dock)  
                    RadDockLayout1.Controls.Add(dock)  
                    dock.DockZoneID = "RadDockZone1" 
                Case 1  
                    'RadDockZone2.Controls.Add(dock)  
                    RadDockLayout1.Controls.Add(dock)  
                    dock.DockZoneID = "RadDockZone2" 
                Case 2  
                    ' RadDockZone3.Controls.Add(dock)  
                    RadDockLayout1.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.  
            CreateSaveStateTrigger(dock)  
 
            'Load the selected widget  
            dock.Tag = chkDockList.Items(index).Value  
            LoadWidget(dock)  
        Next index  
    End Sub 
0
HL
Top achievements
Rank 1
answered on 01 Mar 2010, 09:03 PM
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

Thanks
Helena
0
Pero
Telerik team
answered on 02 Mar 2010, 02:08 PM
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.


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.
Tags
Dock
Asked by
brad
Top achievements
Rank 1
Answers by
Pero
Telerik team
brad
Top achievements
Rank 1
HL
Top achievements
Rank 1
Share this question
or