叮当小说网 找小说网 无限小说网 红尘小说网 幻想小说网 酷文学 深夜书屋

如何不使用让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 方法是获得菜单表数据的方法,在此省略了.

posted on 2007-11-08 13:59  麦哲思科技  阅读(116)  评论(0)    收藏  举报

导航