Saturday, February 25, 2012

ASP.NET(Include Active Class For Page In CSS)


public void activePage()
    {
        //Copyrights...
        copyrightyear.InnerText = DateTime.Now.ToString("yyyy");

        #region ActivePage

        string k = HttpContext.Current.Request.Url.AbsolutePath.ToString();
        string t = k.Substring(k.LastIndexOf("/") + 1, (k.LastIndexOf(".aspx") - 1) - k.LastIndexOf("/")).ToLower();
        switch (t)
        {
            case "default": //pagename
                homepage.Attributes.Add("class", "active");
                break;

            case "exclusiveoffers"://pagename
                exclusiveoffers.Attributes.Add("class", "active");
                break;

            case "blog"://pagename
                blog.Attributes.Add("class", "active");
                break;

            case "aboutus"://pagename
                aboutus.Attributes.Add("class", "active");
                break;

            case "contactus"://pagename
                contactus.Attributes.Add("class", "active");
                break;
        }
        #endregion
    }

No comments:

Post a Comment