询问:导航器,MenuItemClick事件 [英] ASK: Navigator, MenuItemClick event

查看:119
本文介绍了询问:导航器,MenuItemClick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么..每个人..谁能帮助我,

我有一个简单的导航菜单,如下所示:
< asp:菜单ID ="Menu1" runat =服务器" Orientation =水平"
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:菜单>

在后面的代码中,我有事件meniitemclick
受保护的void Menu1_MenuItemClick(object sender,MenuEventArgs e)
{
Page.Title = e.Item.Text;

}

如果我选择没有NavigateUrl的Product-A,则站点中的页面标题已更改.但是,如果我选择除Product-A之外的MenuItemClick事件,则不会执行.是因为它有一个NavigationUrl?

如果我选择了具有NavigationUrl的菜单,并且我选择了菜单,请更改页面标题.网站标题?

对不起,如果我的英语不好^ _ ^

我需要别人的帮助和分享,^ _ ^

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

推荐答案

之前,谢谢.菜单控件不允许这样做..如果您具有导航URL,则Click事件将不会触发..不仅菜单控件而且树视图.

所以你有选择.
(1)在用户控件旁边开发菜单控件,并将其拖放到所需的页面.如果您使用母版页,则只需将其拖到母版页即可.

使用
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

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

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...


这篇关于询问:导航器,MenuItemClick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆