ASP.net菜单控件:menuitemclick和回发 [英] ASP.net menu control: menuitemclick and postback

查看:256
本文介绍了ASP.net菜单控件:menuitemclick和回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我的问题简化为以下问题:

1)菜单页面具有带有子菜单的菜单.某些子菜单项链接到页面B,页面B具有返回按钮,该按钮返回到菜单页面.第B页.

2)页面B需要根据子菜单项将其从菜单页面引导到页面B来更改其中的某些组件,即,根据菜单页面单击的菜单项的不同,页面组件也有所不同.也就是说,页面B = {Components} = diff(menu items)

3)菜单由数据库表中的数据构成.我不喜欢使用XML文件左右.

4)page_load()函数的行如下所示:

Hello fellows,
My question is simplified as bellow:

1) A menu page has a menu with submenus. some of the submenu items links to page B which has a go back button links back to manu page.That means, Menu page <--> page B.

2) Page B need to change some components in it according to which submenu item leads it to Page B from menu page, ie., different page components according to different menu item clicked of menu page. That means, Page B = {Components} = diff(menu items)

3) The menu is constructed with data from a database table. I dont like to use XML file or so.

4) The page_load() function has lines as bellow:

01.if (!Page.IsPostBack)   
02.  {   
03.           String mySel = "select ..... desc";//select menu root items from database   
04.          SqlConnection conn = new SqlConnection(SqlDataSource1.ConnectionString);   
05.          SqlDataAdapter SQLDA = new SqlDataAdapter(mySel, conn);   
06.          conn.Open();   
07.          SqlDataReader SQLDR = SQLDA.SelectCommand.ExecuteReader();   
08.          Menu1.Items.Clear();   
09.          this.Menu1.Orientation = Orientation.Horizontal;   
10.          String GM;   
11.          while (SQLDR.Read())   
12.          {   
13.              GM = SQLDR["menuitem"].ToString();   
14.              MenuItem mi = new MenuItem();   
15.              mi.Text = GM;//menu root get text   
16.          String mySel2 = "select .....";//select submenu items from database.   
17.              SqlConnection conn2 = new SqlConnection(SqlDataSource1.ConnectionString);   
18.              SqlDataAdapter SQLDA2 = new SqlDataAdapter(mySel2, conn2);   
19.              conn2.Open();   
20.              SqlDataReader SQLDR2 = SQLDA2.SelectCommand.ExecuteReader();   
21.              while (SQLDR2.Read())   
22.              {   
23.                  MenuItem mii = new MenuItem();   
24.                  mii.Text = SQLDR2["menusubitems"].ToString();   
25.           //     mii.NavigateUrl = SQLDR2["url"].ToString();    
26.           // the above line should be remarked as comments, otherwise the menuitemclick event could not be reached.   
27.  
28.               // mii.Value = SQLDR2["menusubitems"].ToString();   
29.                  mii.Value = SQLDR2["url"].ToString();   
30.                  mii.Selectable = true;   
31.                  mi.ChildItems.Add(mii); //menusubitem be added   
32.              }   
33.              mi.Selectable = true;   
34.              this.Menu1.Items.Add(mi); //add sub menu to root menu.   
35.              SQLDR2.Close();   
36.              conn2.Close();   
37.          };   
38.  
39.          this.Menu1.Dispose();   
40.          SQLDR.Close();   
41.          conn.Close();   
42.  
43.      }   
44.  } 



如果我没有在其中放置"if(!Page.IsPostBack)",则无法到达menuitemclick事件.如果在此处放置"if(!Page.IsPostBack)",则可以到达该事件,但是在通过menuitemclick事件处理函数通过redirect(url)进入新页面之后,当它返回菜单页面时,该菜单消失了.

我一点都不知道!



if I didnot put " if(!Page.IsPostBack) " there, the menuitemclick event could not be reached. if I put " if(!Page.IsPostBack) " there, the event could be reached, but after getting to the new page from the menuitemclick event handle function through redirect(url), when it go back to the menu page, the menu disappears.

I got no ideas at all!

推荐答案

这是ASP.net页面事件生命周期的全部内容:

[ http://msdn.microsoft.com/en-us/library/ms178472. aspx ]
it''s all part of the ASP.net page event lifecycle:

[http://msdn.microsoft.com/en-us/library/ms178472.aspx]


这篇关于ASP.net菜单控件:menuitemclick和回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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