0

How to set the Active menu item color when i click the sub submenu items or main item in asp.net master page.

My code is (master page source)

<ul class="art-menu">
      <li><a href="#" class="{ActiveItem}"><span class="l"></span><span class="r"></span><span
                            class="t">Submission</span> </a>
                            <ul>
                                <li><a href="../QuoteStatus.aspx">Search Submission</a></li>
                                <li><a href="../NewQuote.aspx">New Submission</a></li>
                            </ul>
                        </li>
                        <li><a href="#"><span class="l"></span><span class="r"></span><span class="t">Requests</span></a>
                            <ul>
                                <li><a href="../Requests/IssueCertificates.aspx">Issue Certificates</a></li>
                                <li><a href="../Requests/QuoteCancellation.aspx">Cancellation</a></li>
                                <li><a href="../Requests/LossRuns.aspx">Loss Runs</a></li>
                                <li><a href="../Requests/Endorsements.aspx">Endorsements</a></li>
                            </ul>
                        </li>
                        <li><a href="#"><span class="l"></span><span class="r"></span><span class="t">Reports</span></a>
                        </li>
                        <li><a href="#"><span class="l"></span><span class="r"></span><span class="t">Configuration</span></a>
                            <ul>
                                <li><a href="../Administration/UserInformation.aspx">User Information</a></li>
                                <li><a href="../SignUp.aspx">New User</a></li>
                                <li><a href="../Administration/AdminSettings.aspx">Admin Settings</a></li>
                            </ul>
                        </li>
</ul>

how to write the code , please give me suggestion about that...

thank u hemanth

1
  • are you put your header in control? Commented Aug 11, 2012 at 12:31

2 Answers 2

4

Here is what I do. There could be a better way. You can try it.

NOTE: your link should have runat="server" so you can access them from code-behind

protected void Page_Load(object sender, EventArgs e)
{            
    string curlink = Request.RawUrl;

    if (curlink.Contains("/administration/school")) 
    {
        schoolinfolink.Attributes["class"] = "selected";
    }
    else if (curlink.Contains("/administration/result"))
    {
        resultlink.Attributes["class"] = "selected";
    }
    else if (curlink.Contains("/administration/staff"))
    {
       staffslink.Attributes["class"] = "selected";
    }

}
Sign up to request clarification or add additional context in comments.

Comments

0

I am not familier to ASP , but in php for instance I'll handle it by adding a function that will check which page is the current page. I will call it above the HTML and then you can use it.

Algorithem:

1.Get current URL

2.Fetch the current file name out of it

3.save the current file name as a variable ("selectedPage")

4.When printing the menu out , use condition to compare the "selectedPage" to the item's file name.

Consider printing the menu using an array and a loop (so instead X conditions , you'll have to write just one)

1 Comment

Will it help I'll write it in php?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.