title: Reading sitemap currentNode from code behind to .addClass('selected') in jQuery not rendering unless it is hard coded?
body: <p>I have a user control that uses two unordered lists with two asp:Repeaters inside to dynamically build a menu from a web.sitemap file. (<a href="http://msdn.microsoft.com/en-us/library/aa581781.aspx#aspnet_tutorial03_masterpagesandsitenav_cs_topic5" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa581781.aspx#aspnet_tutorial03_masterpagesandsitenav_cs_topic5</a>)</p>
  
  <p>Now I want to show the selected MainMenu node and SubMenu node.</p>
  
  <p>To do so, I use jQuery to .addClass('selected') so my selected CSS class can apply to those nodes.  Problem: jQuery will not render selected CSS unless the nodes are hard coded?</p>
  
  <pre><code>&lt;script &gt;
      $(document).ready(function() {  
           String liMenuNodes = ('&lt;%=liTitles %&gt;').toString();
           $(liMenuNodes).addClass('selected');
  
           // This way works but it is hard-coded, it is my desired end result
           // $("li#liInstitutions, li#liSearchInstitutionTypes").addClass('selected');
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>In C# code-behind:</p>
  
  <pre><code>private string liTitleNodes = null;
      public string liTitles 
      { 
          get 
          {
              SiteMapNode currentNode = System.Web.SiteMap.CurrentNode;
              liTitleNodes = ("li#li" + currentNode.ParentNode.Title).Replace(" ", "");
              liTitleNodes += ", ";
              liTitleNodes += ("li#li" + currentNode.Title).Replace(" ", "");
              return liTitleNodes;
          }
      }
  </code></pre>
  
  <p>Eventually, I will move this code to the Site.Master page but cannot get it to work without hard-coding every page :(  I'm wondering if the variable is being passed too late in the page's lifecycle but it looks seems like that isn't the case.</p>
  
  <p>Thanks, 
  Carrie</p>
  
  <hr>
  
  <p>View Source:    </p>
  
  <pre><code>&lt;div id="navigation"&gt;
  &lt;ul id="mainMenu"&gt;
  
              &lt;li id="liHome"&gt;
                  &lt;a href="/ESP2/Default.aspx?p=1"&gt;Home&lt;/a&gt;
                  &lt;ul class="subMenu"&gt;
  
                              &lt;li id="liDashboard"&gt;&lt;a href="/ESP2/Default.aspx"&gt;Dashboard&lt;/a&gt;&lt;/li&gt;
  
                              &lt;li id="liImpersonateUser"&gt;&lt;a href="/ESP2/Default.aspx?p=2"&gt;Impersonate User&lt;/a&gt;&lt;/li&gt;
  
                  &lt;/ul&gt;
              &lt;/li&gt;
  
              &lt;li id="liInstitutions"&gt;
                  &lt;a href="/ESP2/Institutions/SearchInstitutions.aspx?p=1"&gt;Institutions&lt;/a&gt;
                  &lt;ul class="subMenu"&gt;
  
                              &lt;li id="liSearchInstitutions"&gt;&lt;a href="/ESP2/Institutions/SearchInstitutions.aspx"&gt;Search Institutions&lt;/a&gt;&lt;/li&gt;
  
                              &lt;li id="liSearchInstitutionTypes"&gt;&lt;a href="/ESP2/Institutions/SearchInstitutionTypes.aspx"&gt;Search Institution Types&lt;/a&gt;&lt;/li&gt;
  
                  &lt;/ul&gt;
              &lt;/li&gt;
  
      &lt;script &gt;
      $(document).ready(function() { 
          String liMenuNodes = ('li#liInstitutions, li#liSearchInstitutionTypes').toString();
          $(liMenuNodes).addClass('selected');
      });       
      &lt;/script&gt;
  </code></pre>