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

Portal using RadDock like netvibes

4 Answers 129 Views
Dock
This is a migrated thread and some comments may be shown as answers.
NIRAKAR
Top achievements
Rank 1
NIRAKAR asked on 02 Jun 2009, 10:08 AM

Can anybody help me to create raddocks like netvibes?
e.g.
i ve some static docks and i want to create some dynamic docks based on by requirement.

i want to create duplicate docks of static and dynamic both.

All docks states needs to store into database based on users ID.

Whenever user logs in, Users earlier configurations needs to show into the page.


4 Answers, 1 is accepted

Sort by
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 03 Jun 2009, 02:28 PM
You can find a simple example which illustrates how to add dynamically RadDocks and save their state in the session on each collapse/close/expand/move here:
http://demos.telerik.com/aspnet-ajax/dock/examples/myportal/defaultcs.aspx
0
NIRAKAR
Top achievements
Rank 1
answered on 04 Jun 2009, 01:38 PM
dear Obi-Wan Kenobi,

i ve already checked this example, but my requirement is to create some static dock and dynamic docks. Dock states need to store into database and load based on user configuration.

-some animation needs to set.
-create duplicate docks of both static and dynamic docks. also needs to store duplicate states into database, Whenever a user access on next time same configuration should show into the page.

Nirakar.

0
rmoynihan
Top achievements
Rank 1
answered on 04 Jun 2009, 06:35 PM
Hi Nirakar,

Here is an example I posted which loads docks dynamically and uses a loading panel while docks are loaded.

http://www.telerik.com/community/forums/aspnet-ajax/docking/how-can-we-use-radajaxloadingpanel-when-page-goes-postback.aspx

If you want to have static Docks on the page you can either
1)  Place them on the page in design time
2)  Load them before you load the docks which you have saved for the current user in code behind in run time.

Either way on RadDock_Save you will need to remove the static docks from the collection before the collection is saved for that user or else they will be duplicated the next time the page loads or you will get an error because of Raddocks with the same id.

Thanks,

Ronan
0
NIRAKAR
Top achievements
Rank 1
answered on 08 Jun 2009, 08:26 AM
Dear rmoynihan,

in my project i ve created 5 static docks and some dynamic docks wants to create.

Many dynamic docks creating like telerik example.

In dynamic docks having some .ascx files. While reloading the page, how to set all .ascx files into corresponding docks.

remember, my dock states are storinng into database and loading docks based on saving states.

some codes attached here.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web.Security;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Configuration;
using System.Web.Configuration;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;

public partial class Default : System.Web.UI.Page
{
    static int xx = 5;
    int userid = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    private SqlConnection _conn = new SqlConnection(ConfigurationManager.ConnectionStrings["loginConnectionString"].ConnectionString);
    private int _count = 0;
    List<PageWidgetInfo> _pageWidgets;
    protected List<PageWidgetInfo> PageWidgets
    {
        get
        {
            if (_pageWidgets == null)
            {
                _pageWidgets = PageWidgetInfo.SelectPageWidgets(Convert.ToInt32(Session["storeUserID"].ToString()));
                _pageWidgets.Sort();
            }
            return _pageWidgets;
        }
    }
    protected override void OnInit(EventArgs e)
    {

        string validateUser = userid;
            if (string.IsNullOrEmpty(validateUser))
            {

            }
            else
            {
                foreach (PageWidgetInfo pageWidget in PageWidgets)
                {
                    RadDock dock = CreateDock(pageWidget);
                    switch (dock.UniqueName)
                    {
                        case "RadDock1": break;
                        case "RadDock2": break;
                        case "RadDock4": break;
                        case "RadDock5": break;
                        case "RadDock6":
                            if (dock.Resizable == true)
                            {
                                dock.DockMode = Telerik.Web.UI.DockMode.Floating;
                            }
                            else
                            {
                                dock.DockMode = Telerik.Web.UI.DockMode.Docked;
                            }
                            break;
                        default:
                            Control c = LoadControl("login.ascx");
                            dock.ContentContainer.Controls.Add(c);
                            Button label1 = new Button();
                            label1.ID = "Label1";
                            label1.Text = "Duplicate";
                            dock.TitlebarContainer.Controls.Add(label1);
                            label1.Click += new EventHandler(link_command);
                            Button l2 = new Button();
                            l2.ID = "L2";
                            l2.Text = "Edit";
                            dock.TitlebarContainer.Controls.Add(l2);
                            l2.Click += new EventHandler(L2_command);
                            RadDockLayout1.Controls.Add(dock);
                            dock.Commands.Add(new DockCloseCommand());
                            dock.Commands.Add(new DockExpandCollapseCommand());
                            dock.Command += new DockCommandEventHandler(Dock_Command);
                            CreateSaveStateTriggers(dock);
                            break;
                    }
                   
                }
               
                base.OnInit(e);
            }
        }
  
    protected RadDock CreateDock(PageWidgetInfo pageWidgetIn)
    {
        RadDock dock = new RadDock();
        dock.ApplyState(DockState.Deserialize(pageWidgetIn.State));
        dock.ID = pageWidgetIn.ID.ToString();
        //dock.Tag = "login.ascx"; 
        //dock.UniqueName = "Login";


        //Currently, there is a problem with the RadDock command items:
        // if they are not explicitly created, the Command event it not fired.
        dock.Commands.Add(new DockCloseCommand());
        dock.Commands.Add(new DockExpandCollapseCommand());
        dock.Command += new DockCommandEventHandler(Dock_Command);

        return dock;
    }
    protected RadDock CreateDock(string tagName)
    {

        PageWidgetInfo newPageWidget = PageWidgetInfo.Insert(Convert.ToInt32(Session["storeUserID"].ToString()), string.Empty);
        PageWidgets.Add(newPageWidget);

        RadDock dock = CreateDock(newPageWidget);
        dock.Title = "DockDock";
        
        Control c = LoadControl(tagName);
        dock.ContentContainer.Controls.Add(c);

        return dock;
    }
    protected void Dock_Command(object sender, DockCommandEventArgs e)
    {
        if (e.Command.Name == "Close")
        {
            ScriptManager.RegisterStartupScript(
                UpdatePanel1,
                this.GetType(),
                "RemoveDock",
                string.Format("function _removeDock() {{" +
                    "Sys.Application.remove_load(_removeDock);" +
                    "$find('{0}').undock();" +
                    "$get('{1}').appendChild($get('{0}'));" +
                    "$find('{0}').doPostBack('DockPositionChanged');" +
                    "}};" +
                    "Sys.Application.add_load(_removeDock);", ((RadDock)sender).ClientID, UpdatePanel1.ClientID),
                true);
        }
    }
    private PageWidgetInfo FindWidget(int id)
    {
        foreach (PageWidgetInfo info in PageWidgets)
        {
            if (info.ID == id) return info;
        }
        return null;
    }
    private void CreateSaveStateTriggers(RadDock dock)
    {
        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);
    }
    public int FindID(String UserId)
    {

        int IDD;

        SqlCommand command = new SqlCommand("select count(*) from PageWidget WHERE UserID=@idd", _conn);
        command.Parameters.Add("@idd", SqlDbType.Int).Value = UserId;
        _conn.Open();
        IDD = Convert.ToInt32(command.ExecuteScalar().ToString());
        _conn.Close();
        return IDD;

    }
    public int[] countIDD(String UserID)
    {

        int[] IDD = new int[FindID(userid.ToString())];
        int x = 0;
        SqlCommand command = new SqlCommand("select ID from PageWidget WHERE UserID=@idd", _conn);
        command.Parameters.Add("@idd", SqlDbType.Int).Value = UserID;
        _conn.Open();
        SqlDataReader dr = command.ExecuteReader();
        while (dr.Read() || x < IDD.Length)
        {
            IDD[x] = Convert.ToInt32(dr["ID"].ToString());
            x++;
        }

        _conn.Close();
        dr.Close();
        return IDD;
    }
    protected void PathwayViewer_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        //random
        //string cmds = "SELECT top 1 [pathname], [pathway_des], [small_image] FROM [pathways] order by NEWID()";
        //specific
        string cmds = "SELECT top 1 [pathname], [pathway_des], [small_image],ref_title1,ref_title2 FROM [pathways] where categories like '%Signaling%' order by NEWID()";
        PathwayViewer.DataSource = CommonClass.pathdataset(cmds);
    }
    public string DescWithoutParagraph(string description)
    {
        WordOperation Word = new WordOperation();
        string labelText = string.Empty;
        int words = Word.CountWords(description);
        if (words > 100)
        {
            labelText = WordOperation.FirstWords(description, 60);
        }
        else
        {
            labelText = description.ToString();
        }

        return CommonClass.RemoveParagraph(labelText);

    }
    protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)
    {
       
            foreach (PageWidgetInfo pageWidget in PageWidgets)
            {
                e.Indices[pageWidget.DockState.UniqueName] = pageWidget.DockState.Index;
                e.Positions[pageWidget.DockState.UniqueName] = pageWidget.DockState.DockZoneID;
            }
      
    }
    protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)
    {
      
            int IDFind;
            string dockState;
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            List<DockState> stateList = RadDockLayout1.GetRegisteredDocksState();
            L22.Text = stateList.Count.ToString();

            IDFind = FindID(Session["storeUserID"].ToString());
            if (IDFind == 0)
            {

                foreach (DockState state in RadDockLayout1.GetRegisteredDocksState())
                {

                    PageWidgetInfo newPageWidget = PageWidgetInfo.Insert(Convert.ToInt32(Session["storeUserID"].ToString()), state.ToString());
                    PageWidgets.Add(newPageWidget);
                    //Label2.Text += state.ToString();
                }
            }
            else
            {

                int[] no = new int[IDFind];
                int x = 0;
                foreach (DockState state in RadDockLayout1.GetRegisteredDocksState())
                {

                    no = countIDD(userid.ToString());
                    PageWidgetInfo pageWidget = FindWidget(no[x]);
                    if (pageWidget != null)
                    {
                        pageWidget.State = state.ToString();
                        pageWidget.Update();
                        x++;

                    }
                    else
                    {
                        PageWidgetInfo.Delete(no[x]);
                    }

                }
                L22.Text = stateList.Count.ToString();
            }

        }
  
    public void addDock()
    {
        RadDock dock = CreateDock("login.ascx");

        UpdatePanel1.ContentTemplateContainer.Controls.Add(dock);

        CreateSaveStateTriggers(dock);

        ScriptManager.RegisterStartupScript(
            dock,
            this.GetType(),
            "AddDock",
            string.Format(@"function _addDock() {{" +
                "Sys.Application.remove_load(_addDock);" +
                "$find('{1}').dock($find('{0}'));" +
                "$find('{0}').doPostBack('DockPositionChanged');" +
                "}};" +
                "Sys.Application.add_load(_addDock);", dock.ClientID, RadDockZone1.ClientID),
            true);
      
    }
    protected void link_command(object sender, EventArgs e)
    {
        //        addDock();
        L22.Text = "GGGGGGGGGGGGG";
    }
    protected void L2_command(object sender, EventArgs e)
    {
        //        addDock();
        L22.Text = "PPPPPPPPPPP";
    } 
    protected void ButtonAddDock_Click(object sender, EventArgs e)
    {
        addDock();
      
    }

    protected void Duplicate_Click(object sender, EventArgs e)
    {
        //RadDock ee = (RadDock)RadDockLayout1.FindControl("RadDock5");
        //ee.Title = "Duplicate Dock";
        //ee.DockMode = DockMode.Docked;
        //ee.EnableDrag = true;
        //ee.EnableViewState = true;
        //ee.AutoPostBack = true;
        //ee.
        //ee.Dock(RadDockZone2);
        dockDuplicate();

        base.OnInit(e);
        //if (Page.IsPostBack)
        //{
           
         
    }

    public void dockDuplicate()
    {
      
        if (Page.IsPostBack)
        {
            DockState state = RadDock5.GetState();
            state.UniqueName = "NewUniqueName";
            RadDock dock = new RadDock(); ;
            dock.Tag = "CalendarInfo.ascx";
            dock.ApplyState(state);
            Control c = LoadControl("CalendarInfo.ascx");
            dock.ContentContainer.Controls.Add(c);
            RadDockLayout1.Controls.Add(dock);
        }
     
    }
    private void LoadWidget(RadDock dock)
    {
        if (string.IsNullOrEmpty(dock.Tag))
        {
            return;
        }
        Control widget = LoadControl(dock.Tag);
        dock.ContentContainer.Controls.Add(widget);
    }

}



pls check the code, if and solution u ve, guide me....



Nirakar.

Tags
Dock
Asked by
NIRAKAR
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
NIRAKAR
Top achievements
Rank 1
rmoynihan
Top achievements
Rank 1
Share this question
or