ArgumentNullException when adding RadDock in Page_Init

2 posts, 0 answers
  1. apb
    apb avatar
    46 posts
    Member since:
    Nov 2008

    Posted 04 Dec 2009 Link to this post

    Hi,

    I'm getting the folllowing error when adding a RadDock control to a RadDockZone in Page_Init.

    What I'm doing:

    Default.aspx
    ...uses LoadControl() to load -> Layout.ascx (contains a RadDockLayout with a RadDockZone)
    ......Layout.ascx then dynamically creates and adds a RadDock to the zone

    The error only happens if I load the dock in Page_Init. If I load in Page_Load it works.

    The markup from Default.aspx:
    <%@ 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></title>  
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <div> 
            <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">  
            </telerik:RadScriptManager> 
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> 
        </div> 
        </form> 
    </body> 
    </html> 
     

    The code behind from Default.aspx:
    using System;  
    using System.Web.UI;  
     
    public partial class _Default : System.Web.UI.Page  
    {  
        protected void Page_Init(object sender, EventArgs e)  
        {  
            Control layout = LoadControl("Layout.ascx");  
            if (layout != null)  
            {  
                PlaceHolder1.Controls.Add(layout);  
            }  
        }  
    }  
     

    The markup from Default.aspx:
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Layout.ascx.cs" Inherits="Layout" %> 
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
    <telerik:RadDockLayout ID="DockLayout1" runat="server">  
        <table border="1" cellpadding="0" width="800">  
            <tr> 
                <td width="100%" valign="top">  
                    <telerik:RadDockZone ID="DockZone1" runat="server" BorderStyle="None">  
                    </telerik:RadDockZone> 
                </td> 
            </tr> 
        </table> 
    </telerik:RadDockLayout> 
     

    The code behind from Layout.ascx:
    using System;  
    using System.Web.UI;  
     
    using Telerik.Web.UI;  
     
    public partial class Layout : System.Web.UI.UserControl  
    {  
        protected void Page_Init(object sender, EventArgs e)  
        {  
            //this causes error  
            RadDock dock = new RadDock();  
            RadDockZone zone = FindControl("DockZone1"as RadDockZone;  
            zone.Controls.Add(dock);  
        }  
     
        protected void Page_Load(object sender, EventArgs e)  
        {  
            //this works  
            //RadDock dock = new RadDock();  
            //RadDockZone zone = FindControl("DockZone1") as RadDockZone;  
            //zone.Controls.Add(dock);  
        }  
     
    }  
     

    The error I'm getting is:

    Value cannot be null.
    Parameter name: key

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: key

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [ArgumentNullException: Value cannot be null.
    Parameter name: key]
       System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) +44
       System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +7455633
       System.Collections.Generic.Dictionary`2.ContainsKey(TKey key) +4
       Telerik.Web.UI.RadDockLayout.SetRegisteredDockParents(Dictionary`2 parents, Dictionary`2 indices) +317
       Telerik.Web.UI.RadDockLayout.Page_InitComplete(Object sender, EventArgs e) +169
       System.EventHandler.Invoke(Object sender, EventArgs e) +0
       System.Web.UI.Page.OnInitComplete(EventArgs e) +8698006
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +467
    

    The problem seems to be internal to the RadDockLaout control. Any idea what is happening? 

    I'll attach the actual files to a support ticket so you guys can try running them.

    Thanks.

    -Al
  2. apb
    apb avatar
    46 posts
    Member since:
    Nov 2008

    Posted 04 Dec 2009 Link to this post

    Figured it out.

    For some reason docks do not automatically get assigned ID's when created in Page_Init.

    This works:

     

            RadDock dock = new RadDock();  
            dock.ID = "dock1";  
     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top