如何禁用导航菜单控件的子项 [英] How to disable child items of navigationmenu control

查看:64
本文介绍了如何禁用导航菜单控件的子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在母版页上有navigarionmaenu控件。这个母版页适用于某些页面。(例如,Add.aspx,login.aspx)



现在我需要在添加时禁用某些导航菜单控件的子项.aspx。

我该怎么办?有人可以帮帮我吗?

Hi,

I have navigarionmaenu control on master page. This master page is applied to some pages.(Ex.Add.aspx,login.aspx)

Now I need to disable some child items of that navigationmenu control on add.aspx.
How can I do it ? Can someone please help me ?

推荐答案

嗨!



在你想要禁用某些控件的codebehind文件上从Master你需要几个代码字符串。

在你的情况下,对于页面 add.aspx ,有 add.aspx.cs Codebehind文件。

所以在方法PageLoad写道:



Hi!

On codebehind file where you want disabling some controls from Master you need a couple of code strings.
In your case for page add.aspx there are add.aspx.cs Codebehind file.
So there in method PageLoad write:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        var menu = Master.FindControl("NavigationMenu");
        if(menu != null)
        {
            // Here we do explicit convert for accessing to Menu properties
            // And in "Items" we specify Index of item that we want enable/disable
            ((System.Web.UI.WebControls.Menu)menu).Items[5].Enabled = false;
        }
    }
}


这篇关于如何禁用导航菜单控件的子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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