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

Postback in Rad Dock ..

3 Answers 235 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 06 Aug 2007, 02:58 PM
Hi,
    I'm creating various Rad Dock objects dynamically and i'm binding it to the Rad Zone based on the Zoneid (Custom defined value). Here i present the piece of code .. This is working fine .. binding the Rad Dock objects at the runtime .. but the problem is whenever i move the Rad dock to diffrent zone . it is posting back .. which is not the best way to implement it ..

    Kindly assit me to get the functionality that i'm looking for .. (No postback when the Rad Dock object is moved to different Rad Zone)

Sample Code:    
aspx page:

<radDk:RadDockingManager ID="RadDockingManager1" runat="server" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table width="100%" style="height: 100%" cellpadding="0" cellspacing="0" id="trMinis">
<tr>
<telerik:RadDockLayout ID="RadDockLayout1" runat="server" OnLoadDockLayout="RadDockLayout1_LoadDockLayout"
OnSaveDockLayout="RadDockLayout1_SaveDockLayout">
<td valign="top" style="width: 33%">
<table width="100%">
<tr>
<td>
<telerik:RadDockZone ID="RadDockZone1" runat="server" BorderStyle="None" BorderWidth="0px">
</telerik:RadDockZone>
<radG:RadGrid ID="RadGrid1" runat="server">
</radG:RadGrid>
</td>
</tr>
</table>
</td>
<td valign="top" style="width: 33%">
<table width="100%">
<tr>
<td>
<telerik:RadDockZone ID="RadDockZone2" runat="server" BorderStyle="None" BorderWidth="0px">
</telerik:RadDockZone>
</td>
</tr>
</table>
</td>
<td valign="top" style="width: 33%">
<table width="100%">
<tr>
<td align="right" width="100%">
<telerik:RadDockZone ID="RadDockZone3" runat="server" BorderStyle="None" BorderWidth="0px">
</telerik:RadDockZone>
</td>
</tr>
</table>
</td>
</telerik:RadDockLayout>
</tr>
</table>


aspx.cs page

protected void Page_Load(object sender, EventArgs e)
    {
        try
        { 
            int intClientid = 68;
        }
        catch (Exception objExp)
        {
            ErrorLog.WriteError(objExp, "View Minis", strLogin);
        }

    }

    protected void Page_Init(object sender, EventArgs e)
    {
        obj_hm.ClientID = 68;// intClientid;
        objds = obj_hm.Minis_Get(); // A Stored Procedure which will return a Table ...

        Session["objtbl"] = objds.Tables["Minis"];

        int zoneid = 1;

        for (int st = 0; st < objds.Tables["Minis"].Rows.Count; st++)
        {
            string id, text, title;

            id = objds.Tables["Minis"].Rows[st]["MiniID"].ToString();
            title = objds.Tables["Minis"].Rows[st]["Heading"].ToString();
            text = objds.Tables["Minis"].Rows[st]["MiniImage"].ToString();           
           
            RadDock dock = CreateRadDock(id, title, text);

            if (zoneid == 1)
            {
                RadDockZone1.Controls.Add(dock);
                zoneid = zoneid + 1;
            }
            else if (zoneid == 2)
            {
                RadDockZone2.Controls.Add(dock);
                zoneid = zoneid + 1;
            }
            else if (zoneid == 3)
            {
                RadDockZone3.Controls.Add(dock);
                zoneid = 1;
            }           
        }
    }

    private RadDock CreateRadDock(string Number, string Title, string Text)
    {
        rg = new RadGrid();
        rg.ID = Number;
        rg.DataSource = (DataTable)Session["objtbl"];
        //rg.Rebind();

        RadDock radDock = new RadDock();
        radDock.ID = Number;
        radDock.Title = Title;
        //radDock.Text = "<img src='.." + Text + "' alt=''/>";
        radDock.ContentContainer.Controls.Add(rg);    
        radDock.AutoPostBack = true;
        radDock.DockMode = DockMode.Docked;
        return radDock;
    }

    protected void RadDockLayout1_SaveDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        string serializedPositions = serializer.Serialize(e.Positions);
        string serializedIndices = serializer.Serialize(e.Indices);

        HttpCookie positionsCookie = new HttpCookie("DockLayout",
            serializer.Serialize(new string[] { serializedPositions, serializedIndices }));

        positionsCookie.Expires = DateTime.Now.AddDays(1);

        if (Session["Login"] != null)
        {
            Response.Cookies.Add(positionsCookie);
        }
        else
        {
            positionsCookie = new HttpCookie("DockLayout", "");
            Response.Cookies.Add(positionsCookie);
        }
    }
    protected void RadDockLayout1_LoadDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)
    {
        HttpCookie positionsCookie = Request.Cookies["DockLayout"];
        if (!Object.Equals(positionsCookie, null))
        {
            string serializedPositionsAndIndices = positionsCookie.Value;
            if (!string.IsNullOrEmpty(serializedPositionsAndIndices))
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string[] positionsAndIndices = serializer.Deserialize<string[]>(serializedPositionsAndIndices);

                e.Positions = serializer.Deserialize<Dictionary<string, string>>(positionsAndIndices[0]);
                e.Indices = serializer.Deserialize<Dictionary<string, int>>(positionsAndIndices[1]);
            }
        }
    }

    Here i have used a Rad Grid, which will be binded to the Rad Dock dynamically .. No need to use the same control .. U can give me some other sample .. but it should not post back when i move the Rad dock object across the Various Zones ..
    
    Help me to fix this out ... Thanks in Advance

Regards,
Sam

3 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 06 Aug 2007, 03:19 PM
Hi Sam,

The dock postbacks because you set so in your code:
radDock.AutoPostBack = true;

We do so in our online demos because in this way state is preserved on moving the dock to a different zone. You save the state on postback. If you simply move the dock without making a postback, state(the dockzone) will not be preserved in the cookies until a postback occurs.


Best wishes,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sam
Top achievements
Rank 1
answered on 07 Aug 2007, 04:01 AM
Hi Petya,
    Thanks for ur reply .. I commented the Auto post back property and now it is not posting back. But how do i managa the state of the Rad Dock in the Cookie? Is there any way to handle the same at Client Side using Javascripts ???

    Thanks in Advance ...

Regards,
Sam
0
Petya
Telerik team
answered on 07 Aug 2007, 03:26 PM
Hello Sam,

If I correctly understand your scenario, you are dynamically re/creating docks and do not want to postback on moving the docks but you do want to save their state. I believe it would be best if you could keep the radDock.AutoPostBack = true; and merely ajaxify the moving of docks. To achieve this, just place an UpdatePanel on the page and create an async trigger for each dock with controlid the id of each dock and eventname="DockPositionChanged". The same stands if you want to preserve the state of collapsed/expanded, etc. of the dock - you need to make a callback on each command click and therefore you can also create a trigger for each dock with eventname="Command". This online demo demonstrates this approach. The main two differences between the example and your code are that you use cookies to store the state and that as far as I saw from your code you do not add any new docks. If you do have a functionality for adding docks, then this example is just the best fit to take a look at. So, if after these suggestions you still experience problems implementing them, please write us again.


Sincerely yours,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Dock
Asked by
Sam
Top achievements
Rank 1
Answers by
Petya
Telerik team
Sam
Top achievements
Rank 1
Share this question
or