programmatic removal of docks

14 posts, 0 answers
  1. Matthew Timbs
    Matthew Timbs avatar
    17 posts
    Member since:
    Aug 2009

    Posted 02 Sep 2009 Link to this post

    Accidentally posted this in the non-ajax forum, so reposting here...

    Is there a way to programmatically remove all docks from a zone?  I want to initiate this from a button click, preferrably in server side code.
  2. Petko
    Admin
    Petko avatar
    45 posts

    Posted 03 Sep 2009 Link to this post

    Hi Matthew Timbs,

    Hope this code helps you:

    ASPX:
    <form id="form1" runat="server"
           <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
        <div> 
            <telerik:RadDockZone ID="RadDockZone1" runat="server"
                <telerik:RadDock ID="RadDock1" runat="server"></telerik:RadDock> 
                <telerik:RadDock ID="RadDock2" runat="server"></telerik:RadDock> 
            </telerik:RadDockZone> 
             
            <asp:Button ID="Button1" runat="server" Text="Remove Docks" OnClick="Button1_Click"/> 
        </div> 
        </form> 

    Code behind:

        protected void Button1_Click(object sender, EventArgs e) 
        { 
            RadDockZone1.Docks.Clear(); 
        } 


    Kind regards,
    Petko
    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. UI for ASP.NET Ajax is Ready for VS 2017
  4. Matthew Timbs
    Matthew Timbs avatar
    17 posts
    Member since:
    Aug 2009

    Posted 03 Sep 2009 Link to this post

    I could've sworn I didn't have that method.  I have fought this for a day or so.  I did upgrade to the latest version so perhaps that wasn't there in the previous one.

    Thanks so much!
  5. Matthew Timbs
    Matthew Timbs avatar
    17 posts
    Member since:
    Aug 2009

    Posted 04 Sep 2009 Link to this post

    This doesn't seem to work.  It does remove them for the time being, but on next postback they reappear.  When the SaveDockLayout event handler is called, it returns info for the docks that have been removed.

    Any idea why, even after removing them from the zone, the layout still knows about them?  the RadDockLayout's RegisteredDocks is a readonly collection.  how do I clear it?

    --Matt
  6. Vyrban
    Vyrban avatar
    31 posts
    Member since:
    Nov 2008

    Posted 04 Sep 2009 Link to this post

    Why don't you try to close the docks then?
    Something like this:
     <form id="form1" runat="server"
           <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
        <div> 
            <telerik:RadDockLayout ID="RadDockLayout1" runat="server" OnSaveDockLayout="SaveDockLayout" OnLoadDockLayout="LoadDockLayout"
            <telerik:RadDockZone ID="RadDockZone1" runat="server" Width="300px"
                <telerik:RadDock ID="RadDock1" runat="server" DefaultCommands="All"></telerik:RadDock> 
                <telerik:RadDock ID="RadDock2" runat="server" DefaultCommands="All"></telerik:RadDock> 
                <telerik:RadDock ID="RadDock3" runat="server" DefaultCommands="All"></telerik:RadDock> 
                <telerik:RadDock ID="RadDock4" runat="server" DefaultCommands="All"></telerik:RadDock>                                                 
            </telerik:RadDockZone> 
            </telerik:RadDockLayout> 
            <asp:Button ID="Button1" runat="server" Text="Postback"></asp:Button> 
            <asp:Button ID="Button2" runat="server" Text="Remove Docks" OnClick="Button2_Click"></asp:Button> 
        </div> 
        </form> 
    Code:
        private List<DockState> CurrentDockStates 
        { 
            get 
            { 
                //Store the info about the added docks in the session. For real life 
                // applications we recommend using database or other storage medium 
                // for persisting this information. 
                List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStatesDynamicDocks"]; 
                if (Object.Equals(_currentDockStates, null)) 
                { 
                    _currentDockStates = new List<DockState>(); 
                    Session["CurrentDockStatesDynamicDocks"] = _currentDockStates; 
                } 
                return _currentDockStates; 
            } 
            set 
            { 
                Session["CurrentDockStatesDynamicDocks"] = value; 
            } 
        } 
     
        protected void Button2_Click(object sender, EventArgs e) 
        { 
            foreach (RadDock dock in RadDockLayout1.RegisteredDocks) 
            { 
                dock.Closed = true
            } 
        } 
     
        protected void LoadDockLayout(object sender, DockLayoutEventArgs e) 
        { 
            foreach (DockState state in CurrentDockStates) 
            { 
                e.Positions[state.UniqueName] = state.DockZoneID; 
                e.Indices[state.UniqueName] = state.Index; 
            } 
        } 
     
        protected void SaveDockLayout(object sender, DockLayoutEventArgs e) 
        { 
            this.CurrentDockStates = RadDockLayout1.GetRegisteredDocksState(); 
        } 

  7. Matthew Timbs
    Matthew Timbs avatar
    17 posts
    Member since:
    Aug 2009

    Posted 04 Sep 2009 Link to this post

    I've done that. (closed the docks), but my fear is that since closed only sets the CSS style to invisible, my control inside the dock is still getting loaded and the queries it does still are executed.

    I think I've gotten something workable but it feels a little kludgey

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

    Posted 08 Sep 2009 Link to this post

    RadDocks can't be removed if they are created declaratively. The can be "closed" - which mean that they will be hidden(display="none") on the page.

    My suggestion is to create RadDocks dynamically and on each post back to recreate only the RadDocks you want to show.
  9. suresh
    suresh avatar
    30 posts
    Member since:
    Apr 2011

    Posted 03 May 2011 Link to this post

    Hi there,
                 I have created raddock dynamically.i have shown a raddock on page load.i have a button to add raddock in same raddockzone.i have another one button to remove raddock from that zone.my problem is when i using ur method like RaddockZone.dock.clear() all docks from the zone was cleared.what i need is , to remove finally created raddock from that zone not all docks.pls solve my problem.
  10. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 04 May 2011 Link to this post

    Hi Suresh,

    Instead of clearing the docks I would recommend the following approach in removing the docks:
    1. "Remove dock" button is clicked
    2. In its click handler the respective dock is closed, i.e. RadDock.Closed=true and RadDock.Visible = false.
    3. On the next postback the Closed dock is not recreated, and is actually "removed" from the zone

    Kind regards,
    Pero
    the Telerik team

    Browse the vast support resources we have to jump start 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.

  11. jose luis
    jose luis avatar
    20 posts
    Member since:
    Apr 2011

    Posted 29 Aug 2011 Link to this post

    Hello,

    with this approach wich happends if inside the raddock we made some registerscripts, this are still there.

  12. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 01 Sep 2011 Link to this post

    Hi Jose,

    Please note that the ScriptManager.RegisterStartupScript() method outputs the provided script as a direct child of the form element (at its end, as you can see in the attached screenshot) and is thus not connected to the RadDock.

    As I understand, in the content of your RadDocks you have registered client scripts from the code behind. When the docks are closed (their Visible property is set to false), the scripts are still executed, because the RadDocks are hidden, but not removed entirely from the DOM of the page.

    In order to correct this behavior you should check if the corresponding RadDock is visible, before registering the client script. Please find attached my sample project, implementing a RadDock with property Visible set to false and a user control, that registers a client script, loaded in the dock's content. Before the script is registered, a check whether the parent dock is visible, is performed. You can use this sample as a base for your further development.

    Kind regards,
    Slav
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  13. jose luis
    jose luis avatar
    20 posts
    Member since:
    Apr 2011

    Posted 01 Sep 2011 Link to this post

    Thanks for your response below is your project with ajax and master page and the script is not executed.

    Thanks a lot.

    default page
    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="MasterPage.master" CodeFile="Default.aspx.cs" Inherits="_Default" %>
     
     
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <telerik:RadCodeBlock runat="server">
    <script type="text/javascript">
     
        function SendAjaxMessage(argument) {
            var ajaxManager = $find("<%=RadAjaxManager.GetCurrent(Page).ClientID %>");
            ajaxManager.ajaxRequest(argument);
        }
     
        function RadPanelBar_ItemClick(sender, eventArgs) {
                  SendAjaxMessage("addRadDock_ItemClick");
                }
     
    </script>
    </telerik:RadCodeBlock>
        <div>
            <telerik:RadDockLayout runat="server" ID="RadDockLayout1">
                <telerik:RadDockZone runat="server" ID="RadDockZone1" Width="300" MinHeight="200"
                    Style="float: left; margin-right: 20px;">
                </telerik:RadDockZone>
            </telerik:RadDockLayout>
        </div>
        <div>
        <telerik:RadButton ID="RadButtonAdd" runat="server" Text="Add radDock" onclientclicked="RadPanelBar_ItemClick" AutoPostBack="False">
        </telerik:RadButton>
     
        </div>
    </asp:Content>

    default page code behind:
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadAjaxManager AjaxManager = (RadAjaxManager)this.Master.FindControl("RadAjaxManager1");
            AjaxManager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(RadAjaxManager1_AjaxRequest);
            AjaxManager.AjaxSettings.AddAjaxSetting(RadDockLayout1, RadDockLayout1, null);
        }
     
        protected void Create_RadDock()
        {
            UserControl uc = (UserControl)Page.LoadControl("WebUserControl.ascx");
            uc.ID = "WebUserControl1";
            RadDock dock = new RadDock();
            dock.ID = "RadDock1";
            dock.Visible = true;
            dock.ContentContainer.Controls.Add(uc);
            RadDockZone1.Controls.Add(dock);
         
        }
     
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {
            string argument = (e.Argument);
            String[] stringArray = argument.Split(",".ToCharArray());
     
            if (stringArray[0] == "addRadDock_ItemClick")
            {
                Create_RadDock();
     
            }
     
            //code to handle the generic AJAX request
        }
    }

    on the web user control nothing changed except the script is on the page under radscriptblock tag.
  14. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 06 Sep 2011 Link to this post

    Hello Jose,

    Thank you for the additional code from your project. Based on it, I was able to reproduce your issue and to come up with a solution. In your case you have a user control that is loaded dynamically through an Ajax request and a client script that resides in this user control. In such scenarios the client-side code should be evaluated in order to be successfully executed.

    You can evaluate the client scrip via the evalScripts method, exposed by the telerik client static library. Since you have utilized RadAjaxManager in order to Ajaxify the controls on the page, you can register the evaluation script from the code-behind through the method ResponseScripts of the ajax manager.

    You can find attached a sample project, that demonstrates the suggested approach in practice. Note, that I have moved the alert method on the page, as you described. The evaluation script is configured on code-behind of the WebUserControl. Please use the provided sample as a reference to incorporate the requested feature into your actual project.

    Best wishes,
    Slav
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  15. jose luis
    jose luis avatar
    20 posts
    Member since:
    Apr 2011

    Posted 12 Sep 2011 Link to this post

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