1

I have a Master Page containing a div "navcontainer" and when you click on the navigation button it redirects you to another page. Now when it gets to another page I have a

     Master.FindControl("Dashboard").ID = "active";
    
I am wondering if there is a way to set ID = "active" on the click of the navcontainer on the asp side other than on the FindControl() on the code behind;

Here is my code:

         <div id="navcontainer" 
            style="border-style: outset; border-width: thin; background-color: #663300; height: 30px; ">                
            <ul id="navlist" runat="server">
                <li runat ="server" id="Home" >
                    <a href='<%= ResolveUrl("~/Default.aspx") %>' title="Home"> <span>Home</span></a></li>
            <%
                if (_ApplicationAccess("Dashboard")) {
                %>
                <li runat ="server" id="Dashboard">
                    <a href='<%= ResolveUrl("~/Dashboard/Default.aspx") %>' title="Dashboard"><span>Dashboard</span></a></li> 
                <%
                }
            %>
            </ul>
          </div>

Thanks for your help.

UPDATED

What I am trying to do whenever a navigation button is clicked the color of the button gets changed by the .css file. In my .css file is the ID of the control = 'Active' it changes the color of the navigation control. The way I currently set the ID = 'active' is when the navigation control is clicked and its loads the redirected page under the .cs file I have a Master.FindControl("Dashboard").ID = "active" to change the color of the tab. I am trying to see if there is a way to do it on the master page side when the button is clicked to changes to color rather than doing it on the child page something like this:

        <li runat ="server" id="Diabetes">
            <a id="current" href='<%= ResolveUrl("~/Home/Home.aspx") %>' **onClick = "ID=active"** title="Diabetes"><span>Diabetes</span></a></li>  
Nick Manojlovic
  • 1,171
  • 10
  • 30
  • 49
  • Not sure to understand what you want so I write as comment. Can you use jQuery or something like that? Simply attach to document.ready and set the attribute value (using ClientID property to get the "true" ID of your control as assigned by ASP.NET). – Adriano Repetti Mar 07 '12 at 15:42
  • Your question is a little unclear. The only way you can control click behavior on the client side is with JavaScript but you will have to be more specific about what it is exactly that you're trying to achieve to get some more help. – evasilchenko Mar 07 '12 at 15:43
  • @Adriano, check the **UPDATED** I hope it makes sense. – Nick Manojlovic Mar 07 '12 at 15:53
  • @DeviantSeev, check the **UPDATED** I hope it makes sense. – Nick Manojlovic Mar 07 '12 at 15:53
  • Ok, I repeat myself: Simply attach to document.ready and set the attribute value (using ClientID property to get the "true" ID of your control as assigned by ASP.NET). P.S. why ID instead of class? – Adriano Repetti Mar 07 '12 at 15:54

1 Answers1

1

It's a little bit tough to tell what you're asking, but (if I understand you correctly) you could use jQuery to find your control, then modify its ID. Put this on your ASPX page (the one where the markup for "Dashboard" is, whether that's master or child):

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function() {
        $("#<%=Dashboard.ClientID %>").attr("ID", "active");
    });
</script>
Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
  • Do I place this into MasterPage.aspx or the actual Child page ? I have not done much with jQuery. – Nick Manojlovic Mar 07 '12 at 16:10
  • @Nick I've updated the answer. You want to put that javascript on the page where the markup for the "Dashboard" element is. Also, I added the script import line, since you said you haven't used jQuery. You have to import the jQuery libarary from somewhere (in my example, it's in the `/Scripts` folder). – Josh Darnell Mar 07 '12 at 16:20
  • Got it... But when I do this the button is always active then? I want it to only be active and stay active once its navigated to the page of Dashboard. – Nick Manojlovic Mar 07 '12 at 20:01
  • @Nick Correct. I left out the logic of when / if to set that. If it's just based on being on the "Dashboard" page, can you just check the URL? the top 2 answers to [this post](http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-jquery) explain that nicely. You could just do `if ($(location).attr('href') == "You URL here")` – Josh Darnell Mar 07 '12 at 20:12
  • 1
    Awesome. Thank you for your help... Learned a lot... Also started looking into JQuery, COOL STUFF. – Nick Manojlovic Mar 07 '12 at 20:14