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

programmatic removal of docks

13 Answers 240 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Matthew Timbs
Top achievements
Rank 1
Matthew Timbs asked on 02 Sep 2009, 05:00 PM
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.

13 Answers, 1 is accepted

Sort by
0
Petko
Telerik team
answered on 03 Sep 2009, 02:01 PM
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.
0
Matthew Timbs
Top achievements
Rank 1
answered on 03 Sep 2009, 09:23 PM
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!
0
Matthew Timbs
Top achievements
Rank 1
answered on 04 Sep 2009, 01:43 PM
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
0
Vyrban
Top achievements
Rank 1
answered on 04 Sep 2009, 02:52 PM
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(); 
    } 

0
Matthew Timbs
Top achievements
Rank 1
answered on 04 Sep 2009, 02:55 PM
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
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 08 Sep 2009, 02:36 PM
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.
0
suresh
Top achievements
Rank 1
answered on 03 May 2011, 07:19 AM
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.
0
Pero
Telerik team
answered on 04 May 2011, 03:37 PM
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.

0
jose luis
Top achievements
Rank 1
answered on 29 Aug 2011, 05:46 PM
Hello,

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

0
Slav
Telerik team
answered on 01 Sep 2011, 10:18 AM
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 >>

0
jose luis
Top achievements
Rank 1
answered on 01 Sep 2011, 06:27 PM
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.
0
Slav
Telerik team
answered on 06 Sep 2011, 02:49 PM
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 >>

0
jose luis
Top achievements
Rank 1
answered on 12 Sep 2011, 08:42 AM
woks perfect thanks
Tags
Dock
Asked by
Matthew Timbs
Top achievements
Rank 1
Answers by
Petko
Telerik team
Matthew Timbs
Top achievements
Rank 1
Vyrban
Top achievements
Rank 1
Obi-Wan Kenobi
Top achievements
Rank 1
suresh
Top achievements
Rank 1
Pero
Telerik team
jose luis
Top achievements
Rank 1
Slav
Telerik team
Share this question
or