querystring in masterpages - please help

S

suzy

Hello,

I have created a template for my website using the masterpages template
technique.
It's working fine, except when I try to print the value of a querystring
parameter in my HTML code, I get the following error:

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

which is raised from the MasterPage class. It's falling over on the
following line:

if (control.Visible) Controls.Add(control);


Here is the code in my html file.

<MP:MasterPage id="MPContainer" runat="server">
<MP:ContentRegion id="MPHeader" runat="server">My Title</MP:ContentRegion>

<% = Request.QueryString["id"] %>

<MP:ContentRegion id="MPFooter" runat="server">My Footer</MP:ContentRegion>
</MP:MasterPage>
 
B

bruce barker

if your code behind creates dynamic controls you cannot use <% %> blocks in
the apsx. replace your <% = %> with a literal and set with the codebehind,
say in your site base page.

-- bruce (sqlwork.com)


suzy said:
Hello,

I have created a template for my website using the masterpages template
technique.
It's working fine, except when I try to print the value of a querystring
parameter in my HTML code, I get the following error:

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

which is raised from the MasterPage class. It's falling over on the
following line:

if (control.Visible) Controls.Add(control);


Here is the code in my html file.

<MP:MasterPage id="MPContainer" runat="server">
<MP:ContentRegion id="MPHeader" runat="server">My
Title said:
<% = Request.QueryString["id"] %>

<MP:ContentRegion id="MPFooter" runat="server">My
 
S

suzy

hi bruce,

thanks for the reply, i kind of understand what you are saying, but im not
sure how to fix my problem.

i am trying to set the <title> tag in my aspx page depending on a
querystring value, but my template/master page (where the title tag is
defined) is just html.

in my aspx pages i can override the title tag with plain text, but i have no
idea to do what you are suggesting, because i dont know how to reference the
title tag from my aspx page.

nb: i dont know if this matters, but i am using master pages and not page
templates, which means i am not inheriting from a base class page (ie: i
can't use the base method to reference code in my template page)

any ideas? many thanks



bruce barker said:
if your code behind creates dynamic controls you cannot use <% %> blocks in
the apsx. replace your <% = %> with a literal and set with the codebehind,
say in your site base page.

-- bruce (sqlwork.com)


suzy said:
Hello,

I have created a template for my website using the masterpages template
technique.
It's working fine, except when I try to print the value of a querystring
parameter in my HTML code, I get the following error:

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

which is raised from the MasterPage class. It's falling over on the
following line:

if (control.Visible) Controls.Add(control);


Here is the code in my html file.

<MP:MasterPage id="MPContainer" runat="server">
<MP:ContentRegion id="MPHeader" runat="server">My
Title said:
<% = Request.QueryString["id"] %>

<MP:ContentRegion id="MPFooter" runat="server">My
Footer said:
</MP:MasterPage>
 
S

suzy

It's OK, it was easier than I thought it would be.

Many thanks!

suzy said:
hi bruce,

thanks for the reply, i kind of understand what you are saying, but im not
sure how to fix my problem.

i am trying to set the <title> tag in my aspx page depending on a
querystring value, but my template/master page (where the title tag is
defined) is just html.

in my aspx pages i can override the title tag with plain text, but i have no
idea to do what you are suggesting, because i dont know how to reference the
title tag from my aspx page.

nb: i dont know if this matters, but i am using master pages and not page
templates, which means i am not inheriting from a base class page (ie: i
can't use the base method to reference code in my template page)

any ideas? many thanks



bruce barker said:
if your code behind creates dynamic controls you cannot use <% %> blocks in
the apsx. replace your <% = %> with a literal and set with the codebehind,
say in your site base page.

-- bruce (sqlwork.com)


suzy said:
Hello,

I have created a template for my website using the masterpages template
technique.
It's working fine, except when I try to print the value of a querystring
parameter in my HTML code, I get the following error:

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

which is raised from the MasterPage class. It's falling over on the
following line:

if (control.Visible) Controls.Add(control);


Here is the code in my html file.

<MP:MasterPage id="MPContainer" runat="server">
<MP:ContentRegion id="MPHeader" runat="server">My
Title said:
<% = Request.QueryString["id"] %>

<MP:ContentRegion id="MPFooter" runat="server">My
Footer said:
</MP:MasterPage>
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top