• 如何不使用让menu控件不回发(postback)


    写网站首页程序的导航,要用asp.net2.0 的下menu控件,因为绑定数据库十分方便,不过有个问题,就是我采用的iframe来跳转页面,不想整个首页都跳转,不过发现menu控件没有控制回发的属性,每单击就回发一次,挺麻烦的。后来想到一个曲折来实现的办法,在text属性上做文章,代码如下:

    index.aspx页面:

    .....

    <script language=javascript>

    function OpenNewWindow(strUrl)
    {
        document.all.UrlRedirect.src = strUrl;
    }

    </script>

    <asp:Menu ID="Menuindex" runat="server" Orientation="Horizontal"   >
            </asp:Menu>

    ....

    <iframe id ="UrlRedirect" name="UrlRedirect"></iframe>

    .....

    index.aspx.cs

    ......

    protected void Page_Load(object sender, EventArgs e)
        {       
            InitNavigationTree(Menuindex.Items, "0");       
        }

        private void InitNavigationTree(MenuItemCollection menuItemCollection, string sParentID)
        {

            DataView dvw = new DataView();

            MenuItem nodTemp;   

            dvw.Table = getDataAll("select  * from F_menu  where F_PARENTMENUGUID='"+sParentID +"' order by F_ORDER");
            foreach (DataRowView drv in dvw)
            {

                nodTemp = new MenuItem();
                nodTemp.Value = drv["F_MENUGUID"].ToString();
                nodTemp.Text = GetMenuText(drv["F_LINKPAGE"].ToString(),drv["F_MENUNAME"].ToString()) ;
                menuItemCollection.Add(nodTemp);          
                InitNavigationTree(nodTemp.ChildItems, nodTemp.Value);
            }

        }

        private string GetMenuText(string linkTxt,string nameTxt)
        {
            string temp = "<a style='cursor:hand' onclick=OpenNewWindow('" + linkTxt + "')>" + nameTxt + "</a>";
            return temp;
        }

    ..........

    这样menu就不回发了,而只会调用菜单文本上的那个onclick事件。

    注:getDataAll 方法是获得菜单表数据的方法,在此省略了

  • 相关阅读:
    echarts pie 图表 显示的label 中内容 字体大小自定义
    echarts pie 图表当名称太长时
    一个大屏监控的项目
    Web前端优化最佳实践及工具集锦
    分享网页到微信朋友圈的官方接口
    Explaining Delegates in C#
    Explaining Delegates in C#
    Explaining Delegates in C#
    Explaining Delegates in C#
    Explaining Delegates in C#
  • 原文地址:https://www.cnblogs.com/xjb/p/953294.html
Copyright © 2020-2023  润新知