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

Handling Dock Close Command Server-Side

16 Answers 336 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Gareth
Top achievements
Rank 1
Gareth asked on 22 Jul 2008, 09:26 AM
Hi,
Is it possible to handle the default close button on the dock controls toolbar on the server-side?
Regards
Gareth

16 Answers, 1 is accepted

Sort by
0
Sophy
Telerik team
answered on 22 Jul 2008, 10:52 AM
Hi Gareth,

The dock's server-side Command event is fired when postbacks are enabled and any of the control's commands is clicked. You can use the Command event handler to provide implementation for custom commands or to augment the default behavior of the built-in commands. I suggest you take a look at the Command help article for more detailed information on the issue. If you want to handle the dock's close command server side you can use the Command event handler and check whether the Command name is "Close", e.g.:

<telerik:RadDock id="dock1" runat="server" oncommand="dock1_Command"></telerik:RadDock> 
void dock1_Command(object sender, DockCommandEventArgs e)  
{  
     if (e.Command.Name == "Close")  
     {  
     //your code here  
     }  
I you need further assistance, do contact us again.

Best regards,
Sophy
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Tomáš
Top achievements
Rank 1
answered on 17 Feb 2009, 10:18 AM
Hi, everybody!

I'm trying Sophy's suggestion, but I have problem. Event is never fired.

Here is my RadDock:

<telerik:RadDock runat="server" ID="rdDialog" Title="Okno" Closed="true" Left="280px" 
            Width="725px" Top="60px" EnableEmbeddedSkins="False" EnableEmbeddedBaseStylesheet="False" 
            OnCommand="raddock_Command" CommandsAutoPostBack="true" AutoPostBack="true"

And here is event handler:

protected void raddock_Command(object sender, DockCommandEventArgs e) 
        { 
            if (e.Command.Name == "Close"
            { 
               //some code of mine                 
            } 
        } 



0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 17 Feb 2009, 01:21 PM
It seems that the event is not fired when default commands are used. If you declare dock commands everything will be OK.
Try this:
   <telerik:RadDock runat="server"   
            ID="rdDialog" Title="Okno" Closed="true" Left="280px" Width="725px" Top="60px" 
            EnableEmbeddedSkins="False" EnableEmbeddedBaseStylesheet="False"    
            OnCommand="raddock_Command"   
            AutoPostBack="true">    
            <Commands> 
                <telerik:DockCloseCommand AutoPostBack="true" /> 
            </Commands> 
            <ContentTemplate> 
            </ContentTemplate> 
        </telerik:RadDock> 
        <input type="button" value="showDock" onclick="$find('rdDialog').set_closed(false)" /> 
0
Tomáš
Top achievements
Rank 1
answered on 17 Feb 2009, 02:50 PM
It works this way. Thank you, Obi! May the Force be with you :)
0
Stuart
Top achievements
Rank 1
answered on 27 May 2009, 02:36 PM
Hi,

I'm hoping that you might be able to help.

I'm creating docks dynamically and need to handle the 'Close' command serverside. Only issue is I can't access OnCommand server side ... any ideas?

Cheers,
Stuart. 
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 29 May 2009, 02:23 PM
Try to set AutoPostback= true to each command.
Keep in mind that if you create RadDocks dynamically you should recreate them on each Postback/Ajax call in OnInit. If the commands and docks are not recreated the code in the command's handler will not be executed.
0
Stuart
Top achievements
Rank 1
answered on 29 May 2009, 02:29 PM
The problem is not firing the postback - what I need to do is set handle the onclick event server-side.

What I'm trying to do is when the user closes (in my case removes) the dock I want a serverside event to fire to remove it from the database. So when the dock is dynamically created I need to assign an onclick command to call the Server Side sub.

I have changed my application to use a different method but it would still be nice to find out how to acheive this.
0
Petio Petkov
Telerik team
answered on 02 Jun 2009, 12:53 PM
Hello Stuart,

We added animations to RadDock in the last version(2009/Q1 SP2) . There is a bug if the RadDock's EnableAnimation property is set to false and the close event is not fired. The problem is already fixed but the fix will be available in next official release. To fix the problem with the current version, all you need to do is to override the set_closed method as it shown below:
ASPX:
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
    <div> 
    <asp:Label ID="Label1" runat="server"></asp:Label> 
    <telerik:RadDockLayout ID="RadDockLayout1" runat="server">  
        <telerik:RadDockZone ID="RadDockZone1" runat="server">  
            <telerik:RadDock ID="RadDock1" runat="server">  
            </telerik:RadDock> 
        </telerik:RadDockZone>    
    </telerik:RadDockLayout> 
    </div> 
    </form> 
    <script type="text/javascript">  
    //FIX the problem when dock is without animation.  
    var old_SetClosed = Telerik.Web.UI.RadDock.prototype.set_closed;  
    Telerik.Web.UI.RadDock.prototype.set_closed = function(value, playAnimation)  
    {  
           if(value == true)  
           {  
                this._closed = value;  
                var element = this.get_element();  
                element.style.display = "none";  
                this.updateClientState();  
                Telerik.Web.UI.DockCloseCommand.callBaseMethod(this.getCommand("Close"), 'onCommand');  
           }  
           else  
           {  
                old_SetClosed(value, playAnimation);  
           }  
     }  
    </script> 
</body> 
</html> 
 
Codebehind:
 protected override void OnInit(EventArgs e)  
    {  
        base.OnInit(e);  
        DockCloseCommand command = new DockCloseCommand();  
        command.AutoPostBack = true;  
        RadDock1.Commands.Add(command);  
        RadDock1.Command +=new DockCommandEventHandler(RadDock1_Command);  
    }  
    protected void Page_Load(object sender, EventArgs e)  
    {  
 
    }  
    protected void RadDock1_Command(object sender, DockCommandEventArgs e)  
    {  
        Label1.Text = e.Command.Name + " is clicked";  
    } 
Let us know if you have other questions.

All the best,
Petio Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stuart
Top achievements
Rank 1
answered on 02 Jun 2009, 12:57 PM
Hi Petio,

Thanks for the response. I'll try this out!

Cheers,
Stuart.
0
Andy
Top achievements
Rank 1
answered on 04 Sep 2009, 08:07 PM
Hi,

I am creating docks dynamically and need the close command to be handled server-side as well.  Your example works fine granted I know which dock is closed.  In my case I do not.  I need to be able to update a record in the database based on the dock that was closed.  What is the best way I can accomplish this?  Is there a way I can dynamically create an event handler?

Andy
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 07 Sep 2009, 11:40 AM

You should add a close command with AutoPostback = true and handle RadDock's OnCommand event, e.g.

 protected override void OnInit(EventArgs e)  
    {  
        base.OnInit(e);  
        RadDock dock = new RadDock();  
        dock.ID = "newDock";  
          
        DockCloseCommand closeCommand = new DockCloseCommand();  
        closeCommand.AutoPostBack = true;          
        dock.Commands.Add(closeCommand);  
 
        dock.Command += new DockCommandEventHandler(dock_Command);  
        RadDockZone1.Controls.Add(dock);  
    }  
 
    void dock_Command(object sender, DockCommandEventArgs e)  
    {  
        //SAVE TO DB
    } 

Keep in mind that you should recreate the RadDock, its commands and attach its handlers on each postback/ajax call in onInit.

0
Andy
Top achievements
Rank 1
answered on 08 Sep 2009, 09:37 PM
 I was able to get my ID to update the db from the sender.  Thank you, this worked perfectly. 
0
Prashanth
Top achievements
Rank 1
answered on 09 Jan 2013, 08:15 PM
Hi ,


   I have 4 docks on my page . I am trying to close 3 docks on button click of the open dock . Is it possible. Can ypu please rovide me with some suggestion.
0
Slav
Telerik team
answered on 11 Jan 2013, 02:24 PM
Hi Prashanth,

You can close a RadDock on the server-side by setting its property Closed to true. Another option is to retrieve its client-side object and call the function set_closed(true), which will close the dock on the client.

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.
0
Sidhartha
Top achievements
Rank 1
answered on 09 Dec 2014, 02:24 PM
Hi Team,

I am creating Telerik web controls on  a sharepoint web part ( it is typically another web pagedisplayed on the sharepoint portal).

In this I am using the Rad dock to display data. This part is working well. Now My aim is to handle the rad dock close event and store that in the database. How ever I am not able to detect the dock close event. this event is not being raised. My sample code is as follows .


        private RadDock CreateRadDock()
        {
            var dock = new RadDock
            {
                DockMode = DockMode.Docked,
                UniqueName = Guid.NewGuid().ToString().Replace("-", "a")
            };
            dock.ID = string.Format("RadDock{0}", dock.UniqueName);
            
            DockCloseCommand closeCommand = new DockCloseCommand();
            closeCommand.AutoPostBack = true;
            dock.Commands.Add(closeCommand);
            dock.Command += new DockCommandEventHandler(dock_Command);


            dock.Title = "Dock";
            return dock;
        }


        void dock_Command(object sender, DockCommandEventArgs e)
        {
             // my custom code here when this event is fired.
        }



The event is not getting fired.
Please let me know what I am doing wrong.

Thank you

Regards,
Sid
0
Slav
Telerik team
answered on 12 Dec 2014, 09:45 AM
Hello Sidhartha,

Most probably this happens because you generate a different ID for the RadDock instance each time it is created.

You need to set the same ID for the dock on each page load, otherwise the framework will detect it as a new dock control and the event will not be fired.

Regards,
Slav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Dock
Asked by
Gareth
Top achievements
Rank 1
Answers by
Sophy
Telerik team
Tomáš
Top achievements
Rank 1
Obi-Wan Kenobi
Top achievements
Rank 1
Stuart
Top achievements
Rank 1
Petio Petkov
Telerik team
Andy
Top achievements
Rank 1
Prashanth
Top achievements
Rank 1
Slav
Telerik team
Sidhartha
Top achievements
Rank 1
Share this question
or