Exception adding dynamic dock with EnableViewState = false

12 posts, 0 answers
  1. etrich
    etrich avatar
    21 posts
    Member since:
    Aug 2005

    Posted 04 Dec 2007 Link to this post

    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> 
     


  2. etrich
    etrich avatar
    21 posts
    Member since:
    Aug 2005

    Posted 04 Dec 2007 Link to this post

    Steps to reproduce:

    - Hit page
    - Move dock to other zone
    - Press "Make callback" button
  3. etrich
    etrich avatar
    21 posts
    Member since:
    Aug 2005

    Posted 04 Dec 2007 Link to this post

    After some more testing, this has nothing to do with EnableViewState... Exception is thrown with or without ViewState
  4. Sophy
    Admin
    Sophy avatar
    636 posts

    Posted 05 Dec 2007 Link to this post

    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
  5. etrich
    etrich avatar
    21 posts
    Member since:
    Aug 2005

    Posted 05 Dec 2007 Link to this post

    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);  
        } 
  6. Petya
    Admin
    Petya avatar
    869 posts

    Posted 05 Dec 2007 Link to this post

    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
  7. etrich
    etrich avatar
    21 posts
    Member since:
    Aug 2005

    Posted 05 Dec 2007 Link to this post

    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
  8. Petya
    Admin
    Petya avatar
    869 posts

    Posted 06 Dec 2007 Link to this post

    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
  9. etrich
    etrich avatar
    21 posts
    Member since:
    Aug 2005

    Posted 18 Dec 2007 Link to this post

    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.
  10. Sophy
    Admin
    Sophy avatar
    636 posts

    Posted 19 Dec 2007 Link to this post

    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
  11. etrich
    etrich avatar
    21 posts
    Member since:
    Aug 2005

    Posted 19 Dec 2007 Link to this post

    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);

  12. Sophy
    Admin
    Sophy avatar
    636 posts

    Posted 20 Dec 2007 Link to this post

    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
Back to Top