Skip to content
Loading
   
--%>
this is my div
0
  • 0
    Modified version of your menu

       

    Each menu item has its own id (with a sensible name).

    Code for webform1.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebMenuWithHighlightingCurrentpage
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                MyMasterPage mp = (MyMasterPage)Page.Master;
                System.Web.UI.HtmlControls.HtmlGenericControl ctrl;
                ctrl = (System.Web.UI.HtmlControls.HtmlGenericControl)mp.FindControl("menu_reports");
                if (ctrl != null)
                {
                    // option 1
                    ctrl.Attributes.Remove("class");
                    ctrl.Attributes.Add("class", "current_page_item");
                    // option 2
                    //ctrl.Attributes.Add("style", "background-color:yellow");
                }
            }
        }
    }


    Code for webform2.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebMenuWithHighlightingCurrentpage
    {
        public partial class WebForm2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                MyMasterPage mp = (MyMasterPage)Page.Master;
                System.Web.UI.HtmlControls.HtmlGenericControl ctrl =
                    (System.Web.UI.HtmlControls.HtmlGenericControl)mp.FindControl("menu_aboutus");
                if (ctrl != null)
                {
                    // option 1
                    ctrl.Attributes.Remove("class");
                    ctrl.Attributes.Add("class", "current_page_item");
                    // option 2
                    //ctrl.Attributes.Add("style", "background-color:yellow");
                }
            }
        }
    }


    The masterpage is now called MyMasterPage; adjust to your needs.
    0
  • 0
    Dear Friend,

    First of all I am a beginner , That is why these much doubts, Please understand. 

    I am trying to create a website with a good menu bar . If you could advise any better way to get good menu(using javascript) ,It will be very helpful 

    Thank you for your help, but I have few concerns .
    1. MyMasterPage is not get identified in name space ,

    Please see the attachment

    2.
    Below is css for menu , If we give ID for individual items ,I need to define each class over here.
    /* Menu */


    #menu {
    width: 962px;
    height: 50px;
    margin: 0 auto;
    }


    #menu ul {
    margin: 0;
    padding: 0;
    list-style: none;
    }


    #menu li {
    display: block;
    float: left;
    }


    #menu a {
    display: block;
    float: left;
    height: 38px;
    padding: 8px 20px 0 20px;
    text-decoration: none;
    text-transform: none;
    color: #000000;
    }


    #menu a:hover {
    text-decoration: underline;
    }


    #menu .current_page_item 
    {
    background: url(../images/img05.gif) no-repeat;
    }


    #menu .current_page_item a
     {
    background: url(../images/img06.gif) no-repeat right top;
    font-weight: bold;
    }
    0
  • 0
    Just regarding the fact that MyMasterPage is unknown: yes, that is what my master page for the example is called (MyMasterPage.master). Replace MyMasterPage everywhere in my code with the name of your masterpage (without the master extension; e.g. Site for site.master).

    I will see if I can find time tomorrow to come up with a solution for the css that you gave.
    0
  • 0
    The css that you posted in your last post works with the code I gave you; no changes required. I get Reports in bold for webform1.aspx and About Us in bold for webform2.aspx

    As indicated in my earlier post, you need to change MyMasterPage to the name of your masterpage.

    I'm not a javascript person so can't really advise.
    0