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

Dynamic dock creation problem with ascx contents

5 Answers 190 Views
Dock
This is a migrated thread and some comments may be shown as answers.
NMA
Top achievements
Rank 1
NMA asked on 28 Jan 2009, 08:22 AM
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"); 
oDock1.Controls.Add(oCtrl1); 
 
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"); 
oDock2.Controls.Add(oCtrl2); 
 
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"); 
oDock3.Controls.Add(oCtrl3); 
 
RadDockZone oZone3 = DZ3; 
oZone3.Docks.Insert(0, oDock3);   

5 Answers, 1 is accepted

Sort by
0
NMA
Top achievements
Rank 1
answered on 28 Jan 2009, 09:15 AM
Strangely and while experimenting, I changed the insertion statement from
oZone3.Docks.Insert(0, oDock3);   
to
oZone3.Controls.AddAt(0, oDock3);
and everything worked like a charm...

0
Accepted
Nikolay Raykov
Telerik team
answered on 30 Jan 2009, 03:50 PM
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.
0
NMA
Top achievements
Rank 1
answered on 30 Jan 2009, 03:54 PM
Thanks for your reply Nikolay ;)
0
jrit
Top achievements
Rank 1
answered on 01 May 2009, 02:41 AM
Although I appreciate that your answer is correct, I have to say that the requirement of doing this:
MyDockLayout.Controls.Add(myDock);
MyZone.Controls.Add(myDock);

Is not intuitive when the expectation would clearly be that:
MyZone.Controls.Add(myDock);
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.
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 01 May 2009, 01:42 PM
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);
Tags
Dock
Asked by
NMA
Top achievements
Rank 1
Answers by
NMA
Top achievements
Rank 1
Nikolay Raykov
Telerik team
jrit
Top achievements
Rank 1
Obi-Wan Kenobi
Top achievements
Rank 1
Share this question
or