Nick Manojlovic
Nick Manojlovic

Reputation: 1171

Set control to "active" on the href click?

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>  

Upvotes: 1

Views: 1083

Answers (1)

Josh Darnell
Josh Darnell

Reputation: 11433

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>

Upvotes: 1

Related Questions