Error modifying HtmlForm.Controls collection (templated web site)

J

Jeff Dockman

Background:

We needed the ability to create a templated web site that may change in
layout from installation to installation. To accomplish this, we created a
base Page class that all pages in the site inherit from. In addition to
providing basic functionality and security, this Page class modifies the
HtmlForm controls collection in the deriving page to manage the page layout.
The Page class adds LiteralControls to manipulate the page layout (basically
adding table definitions around the controls that were created when
designing the child form) and adds some standard UserControls (toolbar and
login control). The layout could have been directly added to the base Page
class Controls collection, except that the UserControls contain form
elements and must be nested inside of the form (which is created as a child
control on the deriving page).

For the most part, this works well. However, if any of the controls on the
child form contain script blocks (<% %>), the control manipulation throws an
exception:

The Controls collection cannot be modified because the control contains code
blocks (i.e. <%...%>).

So the question is, what are some ways to get around this? I have seen the
suggestion of making all content user controls and only having one form.
Ultimately, this may be the way to go. However, I would prefer to continue
along this path. Is there a way to hook into the form creation and add the
controls as the form is parsed and added to the page?

Thanks,
jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top