Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hy.. everybody.. can anyone help me,,

i have a simple navigator menu like this:
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal"
onmenuitemclick="Menu1_MenuItemClick">
<Items>
<asp:MenuItem Text="Home" NavigateUrl="#" Value="Home"></asp:MenuItem>
<asp:MenuItem Text="Product" NavigateUrl="~/Default.aspx" Value="Product">
<asp:MenuItem Text="Product-A" Value="Product-A"></asp:MenuItem>
<asp:MenuItem Text="Product-B" NavigateUrl="#" Value="Product-B"></asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>

in code behind i have event meniitemclick
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
Page.Title = e.Item.Text;

}

if i selected Product-A which not have a NavigateUrl, page title in site has change. but if i select besides Product-A MenuItemClick event not execute. what because it has a navigateUrl?

can i do, if i select menu who have a navigateUrl and if i select that, change Page Title.Title of site?

sorry if my english not well ^_^

i need somebody help and share, ^_^

thanks before
Posted
Updated 17-Nov-11 17:24pm
v2

1 solution

Menu control does not allow to do that.. if you have navigate URL then the Click event will not fire.. not only menu control but also tree view.

so you have options.
(1) Develop menu control in side the user control and drag and drop to the pages you want. if you use master page it needs drag to master page only.

use
<asp:MenuItem Text="Product"  Value="~/Default.aspx">
and text put in to the session as

C#
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
      {
            string _strClickedMainMenuName = e.Item.Text;
             
            HttpContext.Current.Session.Add("mainItem",_strClickedMainMenuName );
            Response.Redirect(strRedirectionURL); 
      }




master page or pages which drag drop user control that has menu.(it is not nessassy for keep the menu user control in redirection pages as well)
In page load event

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //check the menu is available in session
                if (HttpContext.Current.Session["mainItem"] != null)
                {
                    // take the already selected value and drow the page title
                    Page.Title = HttpContext.Current.Session["mainItem"].ToString();
                }
                
            }
        }


Hope this will help. do not be hesitate to mark if this helps...
 
Share this answer
 
v3
Comments
Ade.Ruyani.Z 18-Nov-11 0:51am    
Thanks dinidusoft, for your solution,, this very help
Ade.Ruyani.Z 18-Nov-11 0:55am    
i thinks this code not use:
string _strClickedMainMenuName = int.Parse(e.Item.Text);
dinidusoft123 18-Nov-11 1:01am    
of course.. it will change as.. a
string _strClickedMainMenuName = e.Item.Text;

and i will change it in solution also...
thnkx..

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