How to set css class on active menu item using a masterpage?

前端 未结 2 964
鱼传尺愫
鱼传尺愫 2021-01-26 04:20

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)

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 04:56

    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)

提交回复
热议问题