Click here to Skip to main content
15,895,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
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 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!
Posted
Updated 15-Nov-10 22:21pm
v2

1 solution

it's all part of the ASP.net page event lifecycle:

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900