Click here to Skip to main content
14,695,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

am using 2 menu control when am clicking on the first menu items i need to get the submenu controls with default redirection to first item of the sub menu control.

when am clicking on the menu item am getting the sub menu item but when am clicking on the sub menu item the total control is getting refreshed and what i selected getting cleared so as a result the sub menu is disappeared .

how to maintain main menu and sub menu when am clicking on the sub menu item.



thankyou

This is the code am using for please help me....

DataRowCollection drcMAINMENU;
    MenuItem mainMENUITEM;
    private PublicMenu objPM = new PublicMenu();
    string Span = "<span class=mainmenu style=font-weight:bold;text-transform:uppercase;font-size: 12px;display: none;>";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Request["parentid"] != null)
            {
                ViewState["Ilocal"] = Convert.ToString(Request["parentid"]);
            }
            if (Request["menuid"] != null)
            {
                ViewState["link"] = Convert.ToString(Request["menuid"]);
            }
           // ctrlMENU.Items[0].Selected = true;
        }
    }
    public void mainMenu()
                       {
        int ilocal = 0;
        DataSet dsMenu = objPM.GetMainMenuDetails();
        drcMAINMENU = dsMenu.Tables[0].Rows;

        mainMENUITEM = new MenuItem(Span + "<span class=Select>Home</span></span>");
        mainMENUITEM.NavigateUrl = ConfigurationSettings.AppSettings["InternalUrl"].ToString() + "Default.aspx";
        ctrlMENU.Items.Add(mainMENUITEM);
        ctrlMENU.ForeColor = System.Drawing.Color.White;
        foreach (DataRow drMAINMENU in drcMAINMENU)
        {
            string strSubMenu = string.Empty;
            string submenuItem = drMAINMENU["MenuId"].ToString();
            mainMENUITEM = new MenuItem("<span class=mainmenu style=font-weight:bold;text-transform:uppercase;font-size: 12px;display: none;>" + drMAINMENU["Title"].ToString() + "</span>");
            ctrlMENU.Items.Add(mainMENUITEM);

            string t_Url = (drMAINMENU["IsExternalLink"].ToString() == "N" && drMAINMENU["IsContent"].ToString() == "Y") ? "Content.aspx?menuid=" + submenuItem : drMAINMENU["ExternalLink"].ToString();
            if (drMAINMENU["IsExternalLink"].ToString() == "N" && drMAINMENU["IsContent"].ToString() == "Y" && drMAINMENU["IsLastLevel"].ToString() == "Y")
            {
                mainMENUITEM.NavigateUrl = ConfigurationSettings.AppSettings["InternalUrl"].ToString() + t_Url;
            }
            else if (drMAINMENU["IsExternalLink"].ToString() == "Y" && drMAINMENU["IsContent"].ToString() == "N" && drMAINMENU["IsLastLevel"].ToString() == "Y")
            {
                mainMENUITEM.NavigateUrl = ConfigurationSettings.AppSettings["InternalUrl"].ToString() + t_Url;
            }

            ilocal = ilocal + 1;
            HtmlAnchor a = (HtmlAnchor)this.FindControl("ctl00_Public_MenuControl1_ctrlMENU_1");
           // a.Attributes.CssStyle = "select";
        }
        if (Session["SubMenuItems"] != null)
        {
            DataSet ds = (DataSet)(Session["SubMenuItems"]);
            if (ds.Tables[0].Rows.Count > 0)
            {
                string Flag = "ID";
                GetSubmenuItems(ds.Tables[0].Rows[0]["MenuId"].ToString(), Flag);
            }
        }
    }
    public void ctrlMENU_MenuItemClick(object sender, MenuEventArgs e)
    {

        string text = e.Item.Text;
        text = text.Remove(0, Span.Length);
        text = text.Replace("</span>", "");
        GetSubmenuItems(text,"NAME");
    }
    private void GetSubmenuItems(string MainMenuItem,string Flag)
    {
        MenuItem childMENUITEM;
        ctrlsubmenu.Items.Clear();
        int ilocal = 0;
        string tUrl;
        string submenu_landingpageurl = "", submenuurl = "";
        DataSet dsSUBMENU = objPM.GetSubMenuDetails(MainMenuItem,Flag);
        //Session["SubMenuItems"] = dsSUBMENU;
        DataRowCollection drcSUBMENU = dsSUBMENU.Tables[0].Rows;
        int blankspacecount = 0;
        string blankspaces;
        foreach (DataRow drSUBMENUITEM in drcSUBMENU)
        {
            blankspaces = "";
            ilocal = Convert.ToInt32(drSUBMENUITEM["parentid"].ToString());
            tUrl = drSUBMENUITEM["IsExternalLink"].ToString() == "Y" ? drSUBMENUITEM["ExternalLink"].ToString() : "Content.aspx";
            ViewState["Url"] = tUrl;
            tUrl = tUrl + "?parentid=" + Server.UrlEncode(ilocal.ToString()) + "&menuid=" + Server.UrlEncode("smenu" + drSUBMENUITEM["Title"].ToString()).Replace(" ", "%20") + "&mid=" + Server.UrlEncode(drSUBMENUITEM["MenuId"].ToString());
            if (drSUBMENUITEM != null)
            {
                submenu.Visible = true;
                string submenustring = "<div class=\"subNav\">";
                submenustring += "<table><tr><td onclick=\"return funRedirect('" + ConfigurationSettings.AppSettings["InternalUrl"].ToString() + tUrl + "');\"><a style=font-weight:bold;text-transform:uppercase;text-decoration:none;>" + drSUBMENUITEM["Title"].ToString() + "</a></td></tr></table>";
                submenustring += "</div>";
                childMENUITEM = new MenuItem(submenustring);
                ctrlsubmenu.Items.Add(childMENUITEM);                
            }
            else
            {
                submenu.Visible = false;
            }
        }
        DataRow drSUBMENUITEM1 = dsSUBMENU.Tables[0].Rows[0];
        for (int i = 0; i <= 0; i++)
        {
            blankspaces = "";
            ilocal = Convert.ToInt32(drSUBMENUITEM1["parentid"].ToString());
            tUrl = drSUBMENUITEM1["IsExternalLink"].ToString() == "Y" ? drSUBMENUITEM1["ExternalLink"].ToString() : "Content.aspx";
            ViewState["Url"] = tUrl;
            tUrl = tUrl + "?parentid=" + Server.UrlEncode(ilocal.ToString()) + "&menuid=" + Server.UrlEncode("smenu" + drSUBMENUITEM1["Title"].ToString()).Replace(" ", "%20") + "&mid=" + Server.UrlEncode(drSUBMENUITEM1["MenuId"].ToString());
            if (drSUBMENUITEM1 != null)
            {
                ctrlsubmenu.Items[0].Selected = true;
                string s=ConfigurationSettings.AppSettings["InternalUrl"].ToString() + tUrl;
                string test="<script>window.location="+s+"</script>";
                Page.ClientScript.RegisterStartupScript(GetType(),"reditrct","funRedirect("+s+")",true);
             //   Page.RegisterClientScriptBlock("redirect",test);
            }
            else
            {
                submenu.Visible = false;
            }
        }
Posted
Updated 2-Jun-13 18:54pm
v3
Comments
   
Can you post that code ?
Member 7741974 2-Jun-13 23:58pm
   
hi Tadit Dash i pasted the code also please help me its very urgent for me

What you seem to be describing is:

<TABLE style="WIDTH: 900px" align=center>
  <TBODY align: center>
  <TR align=center>
    <TD align=center>
    <DIV class="gwhomeMenu">
    <DIV class= "horz_menu">
        <A id=gwhomeMenu_home href="WelcometoGoodwoods.htm">Home</A>
        <A id=gwhomeMenu_aboutus href="AboutGoodWoods.htm">About Us</A>
        <A id=gwhomeMenu_products href="ProductsGoodWoods.htm">Products</A>
        <A id=gwhomeMenu_services href="ServicesGoodWoods.htm">Services</A>
        <A id=gwhomeMenu_contactus href="ContactGoodWoods.htm">Contact Us</A>
        <BR>
    </DIV>
    </DIV>
   </TD>
  </TR>
  <TR>
    <TD height="50"></TD>
  </TR>

  </TBODY>
</TABLE>


Which displays a menubar, with text that changes color, a background image of the button that changes, all onMouseOver.

These functions are from a .js file that I wrote, that was based on another sample. The functions below work with the code above, to display the menu-bar. Properly coded, it will display vertical sub menus-related to the horizontal bar button, with each vertical sub-menu button capable of generating sub horizontal buttons etc.


{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

var vhmen_timeout = 50;

function vhmen_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p.className        = "active";

  if (c.offsetWidth <= 0)
  {
    c.style.position   = "absolute";
    c.style.visibility = "visible";
    c.style.display    = "block";
  }

  var direction = undefined;
  if (p.parentNode && p.parentNode["vhmen_position"] == "x")
    direction = p.parentNode["vhmen_direction"];

  var top   = (c["vhmen_position"] == "y") ?  p.offsetHeight : 0;
  var left1 = (c["vhmen_position"] == "x") ?  p.offsetWidth  : 0;
  var left2 = (c["vhmen_position"] == "x") ? -c.offsetWidth  : 0;
  var left3 = (c["vhmen_position"] == "x") ?  p.offsetWidth  : 0;

  for (; p; p = p.offsetParent)
  {
    if (p.style.position != 'absolute')
    {
      left1 += p.offsetLeft;
      left2 += p.offsetLeft;
      top   += p.offsetTop;
    }
    left3 += p.offsetLeft;
  }

  if (direction)
  {
    left = (direction == 'right') ? left1 : left2;
    c['vhmen_direction'] = direction;
  }
  else
  {
    left = (left3+c.offsetWidth < document.body.offsetWidth) ? left1 : left2;
    c['vhmen_direction'] = (left3+c.offsetWidth < document.body.offsetWidth) ? 'right' : 'left';
  }
  c.style.align = "center";
  c.style.position   = "absolute";
  c.style.visibility = "visible";
  c.style.display    = "block";
  c.style.top        = top +'px';
  c.style.left       = left + 'px';
}

function vhmen_hide_aux(parent, child)
{
  document.getElementById(parent).className        = "parent";
  document.getElementById(child ).style.visibility = "hidden";
  document.getElementById(child ).style.display    = "block";
}

function vhmen_show(e)
{
  var p = document.getElementById(this["vhmen_parent"]);
  var c = document.getElementById(this["vhmen_child" ]);

  vhmen_show_aux(p.id, c.id);

  clearTimeout(c["vhmen_timeout"]);
}

function vhmen_hide()
{
  var c = document.getElementById(this["vhmen_child"]);

  c["vhmen_timeout"] = setTimeout("vhmen_hide_aux('"+this["vhmen_parent"]+"','"+this["vhmen_child" ]+"')",   vhmen_timeout);
}

function vhmen_attach(parent, child, position)
{
  p = document.getElementById(parent);
  c = document.getElementById(child );

  p["vhmen_child"]    = c.id;
  c["vhmen_child"]    = c.id;
  p["vhmen_parent"]   = p.id;
  c["vhmen_parent"]   = p.id;
  c["vhmen_position"] = position;

  p.onmouseover = vhmen_show;
  p.onmouseout  = vhmen_hide;
  c.onmouseover = vhmen_show;
  c.onmouseout  = vhmen_hide;
}

function gwwebmenu_build_aux(parent, child, position)
{
  document.getElementById(parent).className = "parent";

  document.write('<div class="vert_menu" id="'+parent+'_child">');

  var n = 0;
  for (var i in child)
  {
    if (i == '-')
    {
      document.getElementById(parent).href = child[i];
      continue;
    }

    if (typeof child[i] == "object")
    {
      document.write('<a class="parent" id="'+parent+'_'+n+'">'+i+'</a>');
      gwwebmenu_build_aux(parent+'_'+n, child[i], "x");
    }
    else document.write('<a id="'+parent+'_'+n+'" href="'+child[i]+'">'+i+'</a>');
    n++;
  }

  document.write('</div>');

  vhmen_attach(parent, parent+"_child", position);
}


function gwwebmenu_build(menu)
{
  for (var i in menu) gwwebmenu_build_aux(i, menu[i], "y");
}


When trying to debug your page it is helpful to indent your code and make sure to have matching identification areas.
   
v3
Friend better if you urself debug your code...i have also created such menu logic in my website too...i am giving you following hint..

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           mainMenu();
        }
   
Friend better if you urself debug your code...i have also created such menu logic in my website too...i am giving you following hint..

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           mainMenu();
        }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900