Dynamic dock creation problem with ascx contents

6 posts, 1 answers
  1. NMA
    NMA avatar
    13 posts
    Member since:
    Oct 2008

    Posted 28 Jan 2009 Link to this post

    I am trying to create RadDocks dynamically and add them to static RadDockZones in Page_Load but I get the following error:

    "Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request."

    What can be the source of this problem?

    My structure is as follows:

    - I have a master page having a RadScriptManager
    - I have an aspx page that inherits from this master page
    - I have 3 RadDockZones inside a RadDockLayout in this aspx page with ids DZ1, DZ2 and DZ3
    - In the Page_Load function of this aspx page, I am trying to create RadDocks dynamically and add them to these RadDockZones. The contents of these RadDocks are loaded from separate ascx files:

    RadDock oDock1 = new RadDock(); 
    oDock1.Title = "First Dock"
    oDock1.ID = "radDock1"
    Control oCtrl1 = LoadControl("~/Controls/Dock1Contents.ascx"); 
    RadDockZone oZone1 = DZ1; 
    oZone1.Docks.Insert(0, oDock1); 
    RadDock oDock2 = new RadDock(); 
    oDock2.Title = "Second Dock"
    oDock2.ID = "radDock2"
    Control oCtrl2 = LoadControl("~/Controls/Dock2Contents.ascx"); 
    RadDockZone oZone2 = DZ2; 
    oZone2.Docks.Insert(0, oDock2); 
    RadDock oDock3 = new RadDock(); 
    oDock3.Title = "Third Dock"
    oDock3.ID = "radDock3"
    Control oCtrl3 = LoadControl("~/Controls/Dock3Contents.ascx"); 
    RadDockZone oZone3 = DZ3; 
    oZone3.Docks.Insert(0, oDock3);   
  2. NMA
    NMA avatar
    13 posts
    Member since:
    Oct 2008

    Posted 28 Jan 2009 Link to this post

    Strangely and while experimenting, I changed the insertion statement from
    oZone3.Docks.Insert(0, oDock3);   
    oZone3.Controls.AddAt(0, oDock3);
    and everything worked like a charm...

  3. Answer
    Nikolay Raykov
    Nikolay Raykov avatar
    102 posts

    Posted 30 Jan 2009 Link to this post

    Hello Nurettin,

    Yes, indeed the problem is caused by the fact that you you adding the docks through the Docks collection of the dock zone. If you want to add docks dynamically in code-behind you should add them to the Controls collection of both RadDockZone and RadDockLayout.

    Sincerely yours,
    Nikolay Raykov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. NMA
    NMA avatar
    13 posts
    Member since:
    Oct 2008

    Posted 30 Jan 2009 Link to this post

    Thanks for your reply Nikolay ;)
  5. jrit
    jrit avatar
    16 posts
    Member since:
    Jun 2006

    Posted 30 Apr 2009 Link to this post

    Although I appreciate that your answer is correct, I have to say that the requirement of doing this:

    Is not intuitive when the expectation would clearly be that:
    would be enough to dynamically add the dock into the zone.

    And in either case, the exception would be much better replaced by an exception that explains that you have to do this strange thing if you are unable to simplify the requirements for coding it.
  6. Obi-Wan Kenobi
    Obi-Wan Kenobi  avatar
    460 posts
    Member since:
    Aug 2007

    Posted 01 May 2009 Link to this post

    When you add RadDock you should use Controls collection (not Docks),e.g.
    MyDockLayout.Controls.Add(myDock); //This will add RadDock to the Page
    MyZone.Controls.Add(myDock);//This will add RadDock to the Zone. If you use this, you don't need to invoke MyDockLayout.Controls.Add(myDock);
Back to Top