10 Mayıs 2013 Cuma

Masterpage css link class erişimi




--------Masterpage code source---------

<li><a href="home.aspx" id="HomeLink" runat="server"><i class="home"></i> Home</a></li>
<li><a href="Calendar.aspx" id="CalendarLink" runat="server"><i class="calendar"></i>Calendar</a></li>
<li><a href="Bill.aspx" id="BillLink" runat="server"><i class="list"></i>Bills</a></li>



-------Masterpage code behind---------


protected void Page_Load(object sender, EventArgs e)
    {
        SetCurrentPage();
    }

    private void SetCurrentPage()
    {
        var pageName = GetPageName();

        switch (pageName)
        {
            case "home.aspx":
                HomeLink.Attributes["class"] = "current";
                break;
            case "Calendar.aspx":
                CalendarLink.Attributes["class"] = "current";
                break;
            case "Bill.aspx":
                BillLink.Attributes["class"] = "current";
                break;
        }
    }

    private string GetPageName()
    {
        return Request.Url.ToString().Split('/').Last();
    }

Share:

0 yorum:

Yorum Gönder

Blog Arşivi