views:

22

answers:

2

Hi, I have a master page with a bunch of menu like:

<ul id="ulMenu" runat="server">
    <li id="A">
    <li id="B">
    <li id="C">
    ..and so on ..
</ul>

and i have a function in master page which i call from child pages, like:

Master.setCurrentMenu("A");

and in the SetCurrentMenu() of the Masterpage, since I have my < UL > set to run at server, i am changing it dynamically, like:

StringBuilder myMenu = new StringBuilder(ulMenu.InnerHtml);
//replace and add class for current page
myMenu .Replace("<li id=\"" + cp + "\"", "<li class='selected' id=\""+ cp +"\"");
ulMenu.InnerHtml = myMenu.ToString();

(where cp is the "A" in the current context)

This way I am changing the innerHTML and theoretically its supposed to work just fine. but, in my < UL > i have a few server tags in between like <% ... %> so now the asp.net tells me very cheerfully that :

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

What is the best thing I can do in this scenario?

Many thanks!

ps: edited this coz my < ul > were being taken as an html instead of showing up.. hmm

+1  A: 

It's a known issue. I would suggest not using code blocks in this case (it's considered a best practice use as little code blocks as possible).

Irina
yes, I actually nearly hate using code blocks in aspx at all, but the text for menu is being drawn from a database, plus, it needs some operation on them before it can show up so had to do this.I found what I wanted though, this solves my problem: http://stackoverflow.com/questions/186918/c-how-to-change-html-elements-attributes/187023#187023
iamserious
+1  A: 

This link has the correct answer, infact, somebody can delete this question since its a repeated one, I dint realize it.

I finally got this to work via:

http://stackoverflow.com/questions/186918/c-how-to-change-html-elements-attributes/187023#187023

iamserious