Reputation: 41
I have built up an ASP.net site with a masterpage and a number of content pages. I recently added a new menu control to the masterpage so that I can dynamically build up a menu (based on user access level) from code behind and all works, right up until I do a postback, whereby the menu totally disappears.
I currently have the menu build function inside a (!Page.IsPostback) because I get the following error when postback occurs.
"Name cannot begin with the '2' character, hexadecimal value 0x32. Line 1, position 1538."
What I am looking to do is find a way to persist the new dynamically build controls on the masterpage after a postback occurs (or solve the error, either way I will be happy).
Any help would be appreciated.
Upvotes: 1
Views: 824
Reputation: 41
I like to close off my open issues.
After a very long investigation and dialogue with the supplier of the menu control I was able to find and prove a bug within the original control. Apparently a leading numeric (in this case a 2) in some data I provided to build the menu caused the control to play up. I do not know what the cause was or why it failed, but the supplier fixed to control and delivered a new version of the code and all now works well.
Thanks to those who thought about this one.
Upvotes: 0
Reputation:
You must initialize (and add to the control tree) controls always - and not just selectively based on the postback state. So, place that dyn-init code in page-init (OnInit), to execute always, and it should work.
That approach is equivalent to defining an asp.net control inline, within aspx/ascx files - all that markup gets interpreted during Page's OnInit, which is when those controls get added to page's control tree.
Upvotes: 1