Handling Dock Close Command Server-Side

17 posts, 0 answers
  1. Gareth
    Gareth avatar
    13 posts
    Member since:
    Sep 2012

    Posted 22 Jul 2008 Link to this post

    Hi,
    Is it possible to handle the default close button on the dock controls toolbar on the server-side?
    Regards
    Gareth
  2. Sophy
    Admin
    Sophy avatar
    636 posts

    Posted 22 Jul 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tomáš
    Tomáš avatar
    9 posts
    Member since:
    Feb 2009

    Posted 17 Feb 2009 Link to this post

    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                 
                } 
            } 



  5. Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 17 Feb 2009 Link to this post

    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)" /> 
  6. Tomáš
    Tomáš avatar
    9 posts
    Member since:
    Feb 2009

    Posted 17 Feb 2009 Link to this post

    It works this way. Thank you, Obi! May the Force be with you :)
  7. Stuart
    Stuart avatar
    6 posts
    Member since:
    Feb 2009

    Posted 27 May 2009 Link to this post

    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. 
  8. Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 29 May 2009 Link to this post

    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.
  9. Stuart
    Stuart avatar
    6 posts
    Member since:
    Feb 2009

    Posted 29 May 2009 Link to this post

    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.
  10. Petio Petkov
    Admin
    Petio Petkov avatar
    825 posts

    Posted 02 Jun 2009 Link to this post

    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.
  11. Stuart
    Stuart avatar
    6 posts
    Member since:
    Feb 2009

    Posted 02 Jun 2009 Link to this post

    Hi Petio,

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

    Cheers,
    Stuart.
  12. Andy
    Andy avatar
    6 posts
    Member since:
    Aug 2009

    Posted 04 Sep 2009 Link to this post

    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
  13. Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 07 Sep 2009 Link to this post

    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.

  14. Andy
    Andy avatar
    6 posts
    Member since:
    Aug 2009

    Posted 08 Sep 2009 Link to this post

     I was able to get my ID to update the db from the sender.  Thank you, this worked perfectly. 
  15. Prashanth
    Prashanth avatar
    6 posts
    Member since:
    Jan 2013

    Posted 09 Jan 2013 Link to this post

    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.
  16. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 11 Jan 2013 Link to this post

    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.
  17. Sidhartha
    Sidhartha avatar
    1 posts
    Member since:
    Dec 2014

    Posted 09 Dec 2014 Link to this post

    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
  18. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 12 Dec 2014 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017