By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,636 Members | 1,814 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,636 IT Pros & Developers. It's quick & easy.

Custom Page Class

P: n/a
I have a custom page class that adds a menu onto any page that inherits it.
It works fine on a simple page but when I try to implement it on an
exisiting, more complex page I get the error "A control cannot modify its
parents' control collections. " on the following line;

Me.Controls.Add(Header)

In the aspx page I delete all the HTML code and place a panel on the page as
a placeholder. Since it works on a simple page, there's obviously something
about this particular page that's making it fail. I guess I'm looking for a
more high-level explanation of what might cause this issue.

'Base Class Method
Protected Overrides Sub CreateChildControls()

'Write out the title and link up the stylesheet
Dim sbHeader As New System.Text.StringBuilder
With sbHeader
.Append("<html><head> <title>" & strTitle & "</title>")
.Append(LinkStyleSheet)
.Append("</head>")
End With

Header.Text = sbHeader.ToString
Me.Controls.Add(Header)

Me.Controls.Add(Form)

CTMB.ExecuteSecurity = bExecuteSecurity
Form.controls.add(CTMB)

'You need to put a panel on the page to hold everything that you
want displayed in the form
Dim Main As Control = Me.Controls(0) 'Me.FindControl("Main")

If Not Main Is Nothing Then
Me.Form.controls.add(Main)
End If

Me.Form.controls.add(CBMB)

'Close of the HTML
Dim sbFooter As New System.Text.StringBuilder
With sbFooter
.Append("</body></html>")
End With

Footer.Text = sbFooter.ToString
Me.Controls.Add(Footer)

MyBase.CreateChildControls()

End Sub
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.