5 Answers, 1 is accepted
my code
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="save" OnClientClick="getwidth()" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
RadDockLayout radLayout;
private SqlConnection _conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TelerikDockConnectionString"].ConnectionString);
private int _count = 0;
private TextBox txt1;
private Label va;
private RadDockZone rdzPrvni;
private RadDockZone rdzDruhy;
private RadDockZone rdzTreti;
private DropDownList ddlwidget;
//public ArrayList GetZones()
//{
// ArrayList zones = new ArrayList();
// zones.Add(rdzPrvni);
// zones.Add(rdzDruhy);
// zones.Add(rdzTreti);
// return zones;
//}
private List<DockState> CurrentDockStates
{
get
{
//Get saved state string from the database - set it to dockState variable for example
string dockStatesFromDB = "";
_conn.Open();
SqlCommand command = new SqlCommand("select State from States where id=2", _conn);
dockStatesFromDB = command.ExecuteScalar().ToString();
_conn.Close();
List<DockState> _currentDockStates = new List<DockState>();
string[] stringStates = dockStatesFromDB.Split('|');
foreach (string stringState in stringStates)
{
if (stringState.Trim() != string.Empty)
{
_currentDockStates.Add(
DockState.Deserialize(stringState));
}
}
return _currentDockStates;
}
}
private RadDock CreateRadDock()
{
int docksCount = CurrentDockStates.Count;
RadDock dock = new RadDock();
dock.DockMode =
DockMode.Docked;
dock.UniqueName =
Guid.NewGuid().ToString();
dock.ID =
string.Format("RadDock{0}", dock.UniqueName);
dock.Title =
"Dock";
dock.Text =
string.Format("Added at {0}", DateTime.Now);
dock.Width =
Unit.Pixel(300);
dock.Commands.Add(
new DockCloseCommand());
dock.Commands.Add(
new DockExpandCollapseCommand());
return dock;
}
private void CreateSaveStateTrigger(RadDock dock)
{
//Ensure that the RadDock control will initiate postback
// when its position changes on the client or any of the commands is clicked.
//Using the trigger we will "ajaxify" that postback.
dock.AutoPostBack =
true;
dock.CommandsAutoPostBack =
true;
AsyncPostBackTrigger saveStateTrigger = new AsyncPostBackTrigger();
saveStateTrigger.ControlID = dock.ID;
saveStateTrigger.EventName =
"DockPositionChanged";
UpdatePanel1.Triggers.Add(saveStateTrigger);
saveStateTrigger =
new AsyncPostBackTrigger();
saveStateTrigger.ControlID = dock.ID;
saveStateTrigger.EventName =
"Command";
UpdatePanel1.Triggers.Add(saveStateTrigger);
}
private void LoadWidget(RadDock dock)
{
if (string.IsNullOrEmpty(dock.Tag))
{
return;
}
Control widget = LoadControl(dock.Tag);
dock.ContentContainer.Controls.Add(widget);
}
protected void ButtonAddDock_Click(object sender, EventArgs e)
{
RadDock dock = CreateRadDock();
//find the target zone and add the new dock there
RadDockZone dz = rdzPrvni;
dz.Controls.Add(dock);
CreateSaveStateTrigger(dock);
//Load the selected widget in the RadDock control
dock.Tag = ddlwidget.SelectedValue;
LoadWidget(dock);
}
protected void Page_Init(object sender, EventArgs e)
{
//s base.OnInit(e);
//Recreate the docks in order to ensure their proper operation
Panel addControl = new Panel();
Label lblddl = new Label();
lblddl.Text =
"vyberte komponentu ";
ddlwidget =
new DropDownList();
ddlwidget.ID =
"ddlwidget";
ddlwidget.Width = 150;
ddlwidget.Items.Add(
new ListItem("ExchangeRates.ascx", "~/DynamicData/FieldTemplates/ExchangeRates.ascx"));
ddlwidget.Items.Add(
new ListItem("news", "~/DynamicData/FieldTemplates/news.ascx"));
addControl.Controls.Add(lblddl);
addControl.Controls.Add(ddlwidget);
// DropDownList DropDownZone = new DropDownList();
//DropDownZone.DataSource=GetZones();
//DropDownZone.DataValueField="ClientID";
//DropDownZone.Width = 150;
//Label lblddlzone = new Label();
//lblddlzone.Text = "Vyberte zonu ";
//addControl.Controls.Add(lblddlzone);
//addControl.Controls.Add(DropDownZone);
Button btnAddDock = new Button();
btnAddDock.Text =
"Add Dock to zone 1";
btnAddDock.Click +=
new EventHandler(ButtonAddDock_Click);
addControl.Controls.Add(btnAddDock);
Button btnSaveState = new Button();
btnSaveState.Text =
"ulozit pozice ";
btnSaveState.Click +=
new EventHandler(btnSaveState_Click);
radLayout =
new RadDockLayout();
radLayout.EnableViewState =
false;
radLayout.StoreLayoutInViewState =
true;
radLayout.ID =
"RadDockLayout";
radLayout.SaveDockLayout +=
new DockLayoutEventHandler(RadDockLayout1_SaveDockLayout);
radLayout.LoadDockLayout +=
new DockLayoutEventHandler(RadDockLayout1_LoadDockLayout);
rdzPrvni =
new RadDockZone();
rdzPrvni.ID =
"RdzSklady";
rdzPrvni.Orientation =
Orientation.Vertical;
rdzPrvni.MinHeight = 100;
rdzPrvni.Width = 527;
rdzPrvni.CssClass =
"RadDcokZone";
radLayout.Controls.Add(rdzPrvni);
rdzDruhy =
new RadDockZone();
rdzDruhy.ID =
"RdzFinance";
rdzDruhy.MinHeight = 100;
rdzDruhy.Width = 527;
rdzDruhy.CssClass =
"RadDcokZone";
radLayout.Controls.Add(rdzDruhy);
rdzTreti =
new RadDockZone();
rdzTreti.ID =
"RdzInformace";
rdzTreti.CssClass =
"RadDcokZone";
rdzTreti.Width = 527;
rdzTreti.MinHeight = 100;
radLayout.Controls.Add(rdzTreti);
Panel1.Controls.Add(addControl);
Panel1.Controls.Add(radLayout);
for (int i = 0; i < CurrentDockStates.Count; i++)
{
if (CurrentDockStates[i].Closed == false)
{
RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);
radLayout.Controls.Add(dock);
CreateSaveStateTrigger(dock);
LoadWidget(dock);
}
}
}
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.Commands.Add(
new DockCloseCommand());
dock.Commands.Add(
new DockExpandCollapseCommand());
return dock;
}
void btnSaveState_Click(object sender, EventArgs e)
{
}
protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)
{
foreach (DockState state in CurrentDockStates)
{
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
}
protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)
{
List<DockState> stateList = radLayout.GetRegisteredDocksState();
StringBuilder serializedList = new StringBuilder();
int i = 0;
while (i < stateList.Count)
{
serializedList.Append(stateList[i].ToString());
serializedList.Append(
"|");
i++;
}
string dockState = serializedList.ToString();
if (dockState.Trim() != String.Empty)
{
_conn.Open();
SqlCommand command = new SqlCommand(String.Format("update States set State='{0}' where id=2", dockState), _conn);
command.ExecuteNonQuery();
_conn.Close();
}
}
This error is encountered because of AJAX request conflict. When the RadDocks title-bar is clicked many times the DockPositionChanged event is fired more than once. Because the dock's AutoPostBack property is set to true, a couple of AJAX requests are fired even before any previous AJAX post back has finished. This on the other hand generates a duplicate of the RadDock and throws an exception.
You can overcome this error by adding an AJAX Loading Panel that will ensure the AJAX post back to be finished before a new one is started. For your convenience, I have attached a sample project, that shows this can be done.
Please do not hesitate to contact us, if you have any further questions.
Kind regards,
Pero
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.
http://www.bbc.co.uk/home/ if you look on this examples you see that you can move dock how you want and work quick and good.
Do you have some Ideas?
Thanks
Here are a couple ideas to improve the performance of an application that has dynamically created RadDocks:
1. Use a hidden UpdatePanel to add the docks to, so that when a certain RadDock is moved, closed, expanded/collapsed only this RadDock is updated. I have attached a sample project that demonstrates this approach.
2. Another idea is, to load the content inside the RadDocks using WebServices. We do not have such example and you should implement your own way of loading dynamic content through WebService.
3. Save the state of the RadDocks using WebServices. This way you do not have to make AJAX postbacks on every action you perform with the RadDock. We do not have an example that demonstrates this approach, and you should implement it yourself.
Greetings,
Pero
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.