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

Exception adding dynamic dock with EnableViewState = false

11 Answers 153 Views
Dock
This is a migrated thread and some comments may be shown as answers.
etrich
Top achievements
Rank 1
etrich asked on 05 Dec 2007, 01:34 AM

Docks property of RadDockingZone not properly synchronized with Controls property... IndexOutOfRangeException when calling RadDockZone.Controls.Add

    protected void Page_Init(object sender, EventArgs e)  
    {  
          RadDock dock = new RadDock();  
          dock.EnableViewState = false;  
          RadDockZone1.Controls.Add(dock);  
          dock.ID = "FIXED";  
          dock.UniqueName = "FIXED";  
    }  
 
    protected void Button1_Click(object sender, EventArgs e)  
    {  
       RadDockZone1.Controls.Add(new RadDock());  
    } 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
      
    </div> 
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
          <telerik:RadDockLayout ID="RadDockLayout1" Runat="server">  
            
            
          <telerik:RadDockZone ID="RadDockZone2" Runat="server" Height="300px"   
             Width="300px">  
          </telerik:RadDockZone> 
                    <telerik:RadDockZone ID="RadDockZone1" Runat="server" Height="300px"   
             Width="300px">  
          </telerik:RadDockZone> 
 
          </telerik:RadDockLayout> 
          <asp:Button ID="Button1" runat="server" onclick="Button1_Click"   
             Text="Make Callback" /> 
 
    </form> 
</body> 
</html> 
 


11 Answers, 1 is accepted

Sort by
0
etrich
Top achievements
Rank 1
answered on 05 Dec 2007, 01:38 AM
Steps to reproduce:

- Hit page
- Move dock to other zone
- Press "Make callback" button
0
etrich
Top achievements
Rank 1
answered on 05 Dec 2007, 01:48 AM
After some more testing, this has nothing to do with EnableViewState... Exception is thrown with or without ViewState
0
Sophy
Telerik team
answered on 05 Dec 2007, 09:18 AM
Hi Etrich,

The problem you experience is due to the new dock you create at button click event having no id which is needed for the proper functioning of the control. That is why you experience a strange behavior. Please, set id to the new dock you create.

Best wishes,
Sophy
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
etrich
Top achievements
Rank 1
answered on 05 Dec 2007, 02:26 PM
Unfortunately, this has nothing to do with control id. This also raises an exception:

    protected void Page_Init(object sender, EventArgs e)  
    {  
          RadDock dock = new RadDock();  
          RadDockZone1.Controls.Add(dock);  
          dock.ID = "FIXED";  
          dock.UniqueName = "FIXED";  
    }  
 
    protected void Button1_Click(object sender, EventArgs e)  
    {  
       RadDock dock = new RadDock();  
       dock.ID = "SECOND";  
       dock.UniqueName = "SECOND";  
       RadDockZone1.Controls.Add(dock);  
    } 
0
Petya
Telerik team
answered on 05 Dec 2007, 05:34 PM
Hello etrich,

Here is the code I tested with based on the code you provided and I was not able to reproduce any problems:

[ASPX]

            <asp:scriptmanager id="ScriptManager1" runat="server"
            </asp:scriptmanager> 
            <telerik:raddocklayout id="RadDockLayout1" runat="server"
                <telerik:raddockzone id="RadDockZone2" runat="server" height="300px" width="300px"
                </telerik:raddockzone> 
                <telerik:raddockzone id="RadDockZone1" runat="server" height="300px" width="300px"
                </telerik:raddockzone> 
            </telerik:raddocklayout> 
            <asp:button id="Button1" runat="server" onclick="Button1_Click" text="Make Callback" /> 


[C#]

    protected void Page_Init(object sender, EventArgs e) 
    { 
        RadDock dock = new RadDock(); 
        RadDockZone1.Controls.Add(dock); 
        dock.ID = "FIXED"
        dock.UniqueName = "FIXED"
    } 
 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        RadDock dock = new RadDock(); 
        dock.ID = "SECOND"
        dock.UniqueName = "SECOND"
        RadDockZone1.Controls.Add(dock); 
    }  


Would it be possible for you to send us a simple running page reproducing the problem you describe and steps to reproduce it.

All the best,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
etrich
Top achievements
Rank 1
answered on 05 Dec 2007, 11:34 PM
I don't see what more I can send you... I sent you aspx content, code behind and steps to reproduce.

When I display the page, docks shows in bottom zone. I move the dock to top zone, then hit the "make callback" button.

Server Error in '/TestsRadDockCSharp' Application. Index must be within the bounds of the List.Parameter name: index 

ArgumentOutOfRangeException: Index must be within the bounds of the List.  
Parameter name: index]  
   System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +62  
   System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item) +2379656  
   Telerik.Web.UI.RadDockZone.AddedControl(Control control, Int32 index) +152  
   System.Web.UI.ControlCollection.Add(Control child) +146  
   _Default.Button1_Click(Object sender, EventArgs e) in c:\TestsRadDockCSharp\Default.aspx.cs:30  
 


I am running Telerik.Web.UI 2007.2.1107.0
0
Petya
Telerik team
answered on 06 Dec 2007, 02:35 PM
Hi etrich,

I was able to reproduce the problem with the last instructions you sent us. You can avoid it using this piece of code:

protected void Button1_Click(object sender, EventArgs e)
    {
        RadDock dock = new RadDock();
        dock.ID = "SECOND";
        dock.UniqueName = "SECOND";
       
        RadDockLayout1.Controls.Add(dock);
        dock.DockZoneID = "RadDockZone1";

    }

Basically our advice is to use the above approach in dynamic docks scenarios and to manipulate the zone's Controls collection mainly in scenarios with static docks.

Sincerely yours,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
etrich
Top achievements
Rank 1
answered on 18 Dec 2007, 08:13 PM
This works fine, thank you!

There is another point we've encountered in the docks API. In the DockCommandCollection, when using the DockCommandCollection.Insert method to insert a command at a specific position, the command's RadDock property is not properly assigned and this causes side effects.

Only the DockCommandCollection.Add assigns the RadDock property.
0
Sophy
Telerik team
answered on 19 Dec 2007, 02:29 PM
Hi Etrich,

Insert method is not implemented by the DockCommandCollection but is inherited by the List<DockCommand> collection and that is the reason why it appears in the itellisense list of methods. I suggest using the Add method instead the Insert method. Using the Add method the dock commands are inserted in the order in which you add them.

Please, let me know if you need further assistance.

Kind regards,
Sophy
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
etrich
Top achievements
Rank 1
answered on 19 Dec 2007, 04:25 PM
It would be nice to also override the Insert of the DockCommandCollection. We have a scenario where we need to insert a command at a specific index. We are using this hack to accomplish this, using a temporary stack to use the Add method:

//commands.Insert(insertIndex, command);

//HACK: Telerik DockCommandCollection.Insert

Stack<DockCommand> insertFix_Commands = new Stack<DockCommand>();

for (int i = commands.Count - 1; i >= insertIndex; i--)

{

DockCommand insertFix_command = commands[i];

commands.Remove(insertFix_command);

insertFix_Commands.Push(insertFix_command);

}

commands.Add(command);

foreach (DockCommand commandToAdd in insertFix_Commands)

commands.Add(commandToAdd);

0
Sophy
Telerik team
answered on 20 Dec 2007, 02:09 PM
Hi Etrich,

We already implemented the Insert method for the DockCommandCollection and it will be available in the next update of the control - Q3 2007 SP1.

All the best,
Sophy
the Telerik team

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