Server Side Close Command not firing Code

4 posts, 0 answers
  1. Michael
    Michael avatar
    6 posts
    Member since:
    Aug 2010

    Posted 25 Oct 2010 Link to this post

    I am creating the dock dynamuically and for some reason I am having trouble with the DockCommandEventHandler event firing the corresponding c# code in dock_CustomCommand. Did I miss some sort of initialization? Is what I am trying to do possible? 

    C#:
    public void createWinlets(string title, string position, string reference)
        {
            RadDock dock = new RadDock();
            UserControl ascx = (UserControl)Page.LoadControl(reference);
            dock.Title = title;
            dock.DockMode = DockMode.Docked;
            dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
            dock.ID = string.Format("RadDock{0}", dock.UniqueName);
            dock.Width = Unit.Percentage(50);
            dock.Height = Unit.Pixel(275);
            dock.Skin = "Vista";
            dock.EnableDrag = false;
            dock.CommandsAutoPostBack = true;
      
            dock.Commands.Add(new DockCloseCommand());
      
            dock.Command += new DockCommandEventHandler(dock_CustomCommand);
      
            dock.ContentContainer.Controls.Add(ascx);
      
            /*AsyncPostBackTrigger saveStateTrigger = new AsyncPostBackTrigger();
            saveStateTrigger.ControlID = dock.ID;
            saveStateTrigger.EventName = "Command";
            UpdatePanel1.Triggers.Add(saveStateTrigger);*/
      
            switch(position)
            {
                case "Left":
                    dock.Width = Unit.Percentage(48);
                    dock.Height = Unit.Pixel(240);
                    RadDockLeft.Controls.Add(dock);
                    break;
                case "Right":
                    dock.Width = Unit.Percentage(48);
                    dock.Height = Unit.Pixel(240);
                    RadDockRight.Controls.Add(dock);
                    break;
                case "Bottom":
                    dock.Width = Unit.Percentage(99);
                    dock.Height = Unit.Pixel(230);
                    RadDockBottom.Controls.Add(dock);
                    break;
                default:
                    break;
            }
        }
      
        protected void dock_CustomCommand(object sender, DockCommandEventArgs e)
        {
              
            RadDock dock = (RadDock)sender;
            lbl_error.Visible = true;
            lbl_error.Text = "DEBUG: Rad Dock Closed. " + dock.ID + ", " + dock.Title;
        }
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 27 Oct 2010 Link to this post

    Hello Michael,

    In order for the Command server-side event to be fired the state of the dock has to be saved and then applied when the dock is recreated. The event should also be attached on every postback. To demonstrate this I have created a simple project. Please find it attached to the thread.

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael
    Michael avatar
    6 posts
    Member since:
    Aug 2010

    Posted 18 Nov 2010 Link to this post

    Thanks for your example. However it does not allow for my user controls to be shown after postback.   I modified your create widget code to pass in the title and ascx reference location in the project. It seems to load the controls initially but once it has been reloaded I can't see them. Is this a limitaion to the ApplyState Function?
     

    private RadDock CreateRadDockFromState(DockState state)
    {
        RadDock dock = new RadDock();
        dock.DockMode = DockMode.Docked;
        dock.ID = string.Format("RadDock{0}", state.UniqueName);
        dock.ApplyState(state);
        dock.Skin = "Vista";
        dock.EnableDrag = false;
        dock.Commands.Add(new DockCloseCommand());
        dock.Command += new DockCommandEventHandler(dock_Command);
        return dock;
    }
    private RadDock CreateRadDock(string title, string reference)
    {
        int docksCount = CurrentDockStates.Count;
        UserControl ascx = (UserControl)Page.LoadControl(reference);
        RadDock dock = new RadDock();
          
        dock.ContentContainer.Controls.Add(ascx);
        dock.DockMode = DockMode.Docked;
        dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
        dock.ID = string.Format("RadDock{0}", dock.UniqueName);
        dock.Title = title;
        dock.Skin = "Vista";
        dock.EnableDrag = false;
        dock.Commands.Add(new DockCloseCommand());
        dock.Command += new DockCommandEventHandler(dock_Command);
        CreateSaveStateTrigger(dock);
        return dock;
    }
  5. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 23 Nov 2010 Link to this post

    Hi Michael,

    The ApplyState method applies a predefined (or saved) state to a given RadDock. The controls loaded within the dock must be recreated on every postback, if the they are dynamically created. There is no way for us to know what kind of controls are loaded within the dock, and then recreate them on every postback. It is developer's responsibility to recreate the dynamically created controls on trips to the server.
    As you can see in the MyPortal demo, the LoadWidget method is called on every postback. This method loads a user control, and adds it to the ContentContainer of the respective dock.

    Best wishes,
    Pero
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top