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
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.
Thanks so much!
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
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> |
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(); |
} |
I think I've gotten something workable but it feels a little kludgey
--Matt
My suggestion is to create RadDocks dynamically and on each post back to recreate only the RadDocks you want to show.
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.
Instead of clearing the docks I would recommend the following approach in removing the docks:
- "Remove dock" button is clicked
- In its click handler the respective dock is closed, i.e. RadDock.Closed=true and RadDock.Visible = false.
- 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.
with this approach wich happends if inside the raddock we made some registerscripts, this are still there.
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 >>
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.
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 >>