ASP.NET 2.0 help!!

Chameleoki

Limp Gawd
Joined
Jun 28, 2004
Messages
479
This is driving me bonkers and it's probably my lack of understanding but I have this code on a Master Page that adds a control (a saved menu) to the page in the Page_Load:

pnlMenu.Controls.Clear()
Dim myMenu As Menu = CType(Session("Menu"), Menu)
pnlMenu.Controls.Add(myMenu)​

But it throws this error: RegisterRequiresControlState can only be called before and during PreRender. on the last line. The session menu I know works because I can call it and go through all the items, add menu items, etc without problems.

Yet, this does work without errors:

pnlMenu.Controls.Clear()
Dim myMenu As New Menu
pnlMenu.Controls.Add(myMenu)​

I've tried putting this in the Pre_Init, Pre_Render, etc. but same error. If someone knows what I'm doing wrong I would be incredibly grateful!
 
Back
Top