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

Dynamicly radDocking persisting problem

2 Answers 117 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Umut
Top achievements
Rank 1
Umut asked on 24 Nov 2010, 12:14 PM
hello ,

i am trying to create dynamic grid listing setting page. User will configre their report and grid options. and u ser can set grid column order and header text using dock.

1- but i have problem about that because i am creating docking dynamicly, and creating TitlebarTempalte dynamicly and creating ContentTempalte dynamicly, but when user fill the content , i cant reach docks content over the server button.

2- In demos, they show us keep dock state infos Using Session. But i need use ViewState. Not Session.When I change Session to ViewState .net error serialaziton problem.


Thats my code :

 

private RadDock CreateRadDock(String columnName)

 

{

 

RadDock dock = new RadDock();

 

dock.DockMode =

DockMode.Docked;

 

dock.EnableViewState =

true;

 

dock.EnableAnimation =

true;

 

dock.UniqueName =

Guid.NewGuid().ToString().Replace("-", "a");

 

dock.ID =

string.Format("RadDock{0}", dock.UniqueName);

 

dock.Title = columnName;

dock.Text = columnName;

dock.Width = System.Web.UI.WebControls.

Unit.Percentage(100);

 

dock.EnableRoundedCorners =

true;

 

dock.ExpandText =

"Settings";

 

 

dock.Commands.Add(

new DockCloseCommand());

 

System.Web.UI.WebControls.

Image mg = new System.Web.UI.WebControls.Image();

 

mg.Style.Add(

"float", "left");

 

mg.ImageUrl =

"~/Image/information.png";

 

mg.ID =

"mg" + dock.ID;

 

dock.TitlebarTemplate = new TitleBarTemplate(dock.Text);

 

dock.TitlebarContainer.Controls[0].FindControl(

"PanelForTitle").Controls.Add(mg);

 

 

 

 

 

dock.ContentTemplate =

new ContentTemplate(dock.Text);

 

 

return

 

dock;

 

}


 

public

 

class ContentTemplate : ITemplate

 

 

 

 

{

 

 

Panel pContainer = new Panel();

 

 

Panel pControls = new Panel();

 

 

CheckBox chkIsHidden = new CheckBox();

 

 

String columnName = String.Empty;

 

 

public ContentTemplate(String columnName)

 

{

 

this.columnName = columnName;

 

}

 

 

public void InstantiateIn(Control container)

 

{

 

Table tbl = new Table();

 

 

TableRow row = null;

 

 

TableCell cell = null;

 

 

 

// NEW ROW FOR HEADER TEXT

 

 

 

 

 

// ROW 1 (HEADER TEXT)

 

 

 

 

 

//LABEL

 

 

 

 

row =

new TableRow();

 

cell =

new TableCell();

 

 

Label lblText = new Label();

 

lblText.ID =

"lblTitle";

 

lblText.CssClass =

"rdcontent";

 

lblText.Text =

"Kolon Bal : ";

 

cell.Controls.Add(lblText);

row.Controls.Add(cell);

 

// TEXTBOX

 

 

 

 

cell =

new TableCell();

 

 

TextBox tb = new TextBox();

 

tb.Text =

this.columnName;

 

tb.ID =

"txtHeader";

 

tb.AutoPostBack =

true;

 

tb.MaxLength = 100;

tb.Width =

new System.Web.UI.WebControls.Unit(200);

 

cell.Controls.Add(tb);

row.Controls.Add(cell);

tbl.Controls.Add(row);

 

// ROW 2 (HIDDEN STATUS)

 

 

 

 

row =

new TableRow();

 

 

//LABEL

 

 

 

 

cell =

new TableCell();

 

lblText =

new Label();

 

lblText.ID =

"lblHidden";

 

lblText.CssClass =

"rdcontent";

 

lblText.Text =

"Gizli Kolon ";

 

cell.Controls.Add(lblText);

row.Controls.Add(cell);

 

//CHECKBOX

 

 

 

 

cell =

new TableCell();

 

 

CheckBox chkIsHidden = new CheckBox();

 

chkIsHidden.ID =

"cbIsHidden";

 

chkIsHidden.Checked =

false;

 

cell.Controls.Add(chkIsHidden);

row.Controls.Add(cell);

tbl.Controls.Add(row);

 

// ROW 3 (FILTER)

 

 

 

 

row =

new TableRow();

 

 

//LABEL

 

 

 

 

cell =

new TableCell();

 

lblText =

new Label();

 

lblText.ID =

"lblFilter";

 

lblText.CssClass =

"rdcontent";

 

lblText.Text =

"Filtreye Dahil Et ";

 

cell.Controls.Add(lblText);

row.Controls.Add(cell);

 

//CHECKBOX

 

 

 

 

cell =

new TableCell();

 

 

CheckBox chkIsFilter = new CheckBox();

 

chkIsFilter.ID =

"cbIsFilter";

 

chkIsFilter.Checked =

false;

 

cell.Controls.Add(chkIsFilter);

row.Controls.Add(cell);

tbl.Controls.Add(row);

pControls.ID =

"PanelForContent";

 

pControls.Controls.Add(tbl);

container.Controls.Add(pControls);

}

}




 

public class TitleBarTemplate : ITemplate

 

{

 

Label lblText = new Label();

 

 

Panel pContainer = new Panel();

 

 

Panel pControls = new Panel();

 

 

String columnName = String.Empty;

 

 

 

public TitleBarTemplate(String columnName)

 

{

 

this.columnName = columnName;

 

}

 

public void InstantiateIn(Control container)

 

{

 

Literal l;

 

lblText.ID =

"lblTitleText";

 

lblText.Text =

this.columnName;

 

pControls.ID =

"PanelForTitle";

 

l =

new Literal();

 

l.Text =

"<table style='float: left;'><tr><td class='rdcontent'>";

 

pContainer.Controls.Add(l);

pContainer.Controls.Add(lblText);

l =

new Literal();

 

l.Text =

"</td><td>";

 

pContainer.Controls.Add(l);

pContainer.Controls.Add(pControls);

l =

new Literal();

 

l.Text =

"</td></tr></table>";

 

pContainer.Controls.Add(l);

container.Controls.Add(pContainer);

}

}



after that i raise on page_int to keep dock states :

 

protected void Page_Init(object sender, EventArgs e)

 

{

 

//// check source is changing

 

 

////Recreate the docks in order to ensure their proper operation

 

 

 

for (int i = 0; i < CurrentDockStates.Count; i++)

 

{

 

RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);

 

 

//We will just add the RadDock control to the RadDockLayout.

 

 

// You could use any other control for that purpose, just ensure

 

 

// that it is inside the RadDockLayout control.

 

 

// The RadDockLayout control will automatically move the RadDock

 

 

// controls to their corresponding zone in the LoadDockLayout

 

 

// event (see below).

 

RadDockLayout1.Controls.Add(dock);

 

//We want to save the dock state every time a dock is moved.

 

CreateSaveStateTrigger(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. by mr@h

 

 

//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 RadDock CreateRadDockFromState(DockState state)

 

{

 

RadDock dock = new RadDock();

 

dock.DockMode =

DockMode.Docked;

 

dock.ID =

string.Format("RadDock{0}", state.UniqueName);

 

dock.ApplyState(state);

System.Web.UI.WebControls.

Image mg = new System.Web.UI.WebControls.Image();

 

mg.Style.Add(

"float", "left");

 

mg.ImageUrl =

"~/Image/information.png";

 

mg.ID =

"mg" + dock.ID;

 

 

//dock.Commands.Add(new DockExpandCollapseCommand());

 

 

 

return dock;

 

}



..


well, you can see textboxes and check boxes in the dock content template. there is a button in the page,and i need all text box and check values inside docks for create xml setting file by using c#

and i dont need the keep state infos into session. i want ViewState.


 

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;

 

}

}



pls help me. thanks

2 Answers, 1 is accepted

Sort by
0
Umut
Top achievements
Rank 1
answered on 24 Nov 2010, 03:21 PM
can anyone help us?
0
Pero
Telerik team
answered on 25 Nov 2010, 02:56 PM
Hi Umut,

Straight to your questions:

1. The controls created when instantiating the ContentTemplate of the RadDock are added to the Controls collection of the RadDock's ContentContainer. So you can access the controls within the ContentContainer, by using the FindControl method. I have create a sample project to demonstrate this. Here is the full source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="RadScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        //Put your JavaScript code here.
    </script>
    <div>
        <telerik:RadDockLayout ID="RadDockLayout1" runat="server">
            <telerik:RadDockZone ID="RadDockZone1" runat="server" MinHeight="300px" Width="300px">
                <telerik:RadDock ID="RadDock1" runat="server" Title="RadDock-Title" Width="300px">
                </telerik:RadDock>
            </telerik:RadDockZone>
        </telerik:RadDockLayout>
        <asp:Button Text="Get TextBox Value" ID="Button1" runat="server"
            onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
 
public partial class Default : System.Web.UI.Page
{
    protected void Page_Init(object sender, EventArgs e)
    {
        RadDock1.ContentTemplate = new DockTemplate(RadDock1);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Text = ((TextBox)RadDock1.ContentContainer.FindControl("txt1")).Text;
    }
}
 
public class DockTemplate : ITemplate
{
    RadDock dock;
    TextBox txt1;
    Label lbl1;
 
    public DockTemplate(RadDock dock)
    {
        this.dock = dock;
    }
 
    #region ITemplate Members
 
    public void InstantiateIn(Control container)
    {
        txt1 = new TextBox();
        txt1.ID = "txt1";
        txt1.Text = "InitalText";
 
        lbl1 = new Label();
        lbl1.ID = "lbl1";
        lbl1.Text = "City:";
 
        container.Controls.Add(lbl1);
        container.Controls.Add(txt1);
    }
 
    #endregion
}

2. We are using Session in our demos, because the ViewState is not available in the Page.Init when the docks are recreated. As can be seen in the following article from MSDN the ViewState is loaded after the Page.Init stage. You can use any type of storage medium to save the DockState, but you need to make sure that the data is available at Page.Init, and RadDockLayout.SaveDockLayout events.

Sincerely yours,
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.
Tags
Dock
Asked by
Umut
Top achievements
Rank 1
Answers by
Umut
Top achievements
Rank 1
Pero
Telerik team
Share this question
or