CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 7/25/2007 3:58:02 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 5 Views: 41 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
6 Items, 1 Pages 1 |< << Go >> >|
jleviaguirre
Asp.Net User
Controlling ASP.NET Menus Programmatically (how to programatically navigate from a menu?)7/25/2007 3:58:02 AM

0/0

This nice article explains how to synchronize two menus. In my case i put one horizontal and the other vertical but I am stuck in a very simple task (I am a beginner) 

 how do I make it to navigate to the mapped page when clicking the second menu? I realize that that is the way is supposed to work because at the end of the article it says that it catches the click event instead of navigating to any location:

The preceding code catches the click event of Menu1. Instead of navigating to any location, you use the value to determine what the second Menu control displays. You accomplish that by adjusting the StartingNodeUrl property of the second Menu control's SiteMapDataSource control.

I tweaked a little bit the code but don't know if that's the cause.

I want to either navigate to an aspx page or load a control into the content placeholder in Default.aspx when clicking an item from the second menu.

 

Please help Ick! 

 

 

Here are the files:

Web.sitemap

1    <?xml version="1.0" encoding="utf-8" ?>
2    <siteMap>
3      <siteMapNode title="ROOT">
4        <siteMapNode title="Browse Projects">
5          <siteMapNode title="Search" url="searchProjects.aspx"/>
6          <siteMapNode title="View Workflows" url="viewWorkflows.aspx"/>
7          <siteMapNode title="View Projects" url="viewProjects.aspx"/>
8          <siteMapNode title="View Teams" url="viewTeams.aspx"/>
9        </siteMapNode>
10       <siteMapNode title="Manage Projects">
11         <siteMapNode title="Enter new Project" url="Pages/newProject.aspx"/>
12         <siteMapNode title="Enter new Workflow" url="Pages/newWorkflow.aspx"/>
13       </siteMapNode>
14       <siteMapNode title="My GKD">
15         <siteMapNode title="My Projects" url="myProjects.aspx"/>
16         <siteMapNode title="Edit Profile" url="myProfile.aspx"/>
17       </siteMapNode>
18     </siteMapNode>
19   </siteMap>
 
 MasterPage.master.cs 
1    using System;
2    using System.Data;
3    using System.Configuration;
4    using System.Collections;
5    using System.Web;
6    using System.Web.Security;
7    using System.Web.UI;
8    using System.Web.UI.WebControls;
9    using System.Web.UI.WebControls.WebParts;
10   using System.Web.UI.HtmlControls;
11   
12   public partial class MasterPage : System.Web.UI.MasterPage {
13       protected void Menu_Top_MenuItemClick(object sender, MenuEventArgs e) {
14           {
15               switch (e.Item.Value) {
16                   case "Browse Projects":
17                       SiteMapDataSourceGKD2.StartingNodeUrl = "searchProjects.aspx";
18                       return;
19                   case "Manage Projects":
20                       SiteMapDataSourceGKD2.StartingNodeUrl = "Pages/newProject.aspx";
21                       return;
22                   case "My GKD":
23                       SiteMapDataSourceGKD2.StartingNodeUrl = "myProjects.aspx";
24                       return;
25               }
26           }
27       }
28       protected void Menu_Left_MenuItemClick(object sender, MenuEventArgs e) {
29           MenuItem m = Menu_Left.SelectedItem;
30           string tmp = "&lt;li>" + m.Target +
31               "&lt;li>" + m.NavigateUrl +
32               "&lt;li>" + m.Value +
33               "&lt;li>" + m.parent +
34               "&lt;li>" + m.Value +
35               "&lt;li>" + m.ValuePath;/* +
36               "<li>" + m.Parent.NavigateUrl +
37               "<li>" + m.Parent.Target +
38               "<li>" + m.Parent.Value;
39           */
40           contentPlaceHolder.Controls.Add(new LiteralControl(tmp));
41   
42           //Response.Write(tmp);
43           //Response.Redirect();
44       }
45   }
 

MasterPage.master

1    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
2    
3    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4    
5    <html xmlns="http://www.w3.org/1999/xhtml" >
6    <head runat="server">
7        <title>GKD Geochemical Knowledge Desktop</title>
8        <link href="css_gks/Master.css" rel="stylesheet" type="text/css" />
9    </head>
10   <body style="margin:0;height:100%">
11       <form id="form1" runat="server">
12           <table id="masterViewPort" cellpadding="0";cellspacing="0" border="0">
13               <tr>
14                   <td colspan="3" style="background-image: url(img_gks/banner_back.gif); height: 20px; color:#fff; font-weight: bold; font-size: small; width: 100%; text-align: right;">
15                       Geochemical Knowledge Desktop Ver 2007.07.23 [Development]
16                   </td>
17               </tr>
18               <tr>
19                   <td style="height:100%; vertical-align: top; background-color: #e7efff; border-right: #d7e1f6 1px solid; text-align: center;">
20                       <div style="width: 100%; height: 77px; background-color: #336699; text-align: center; font-size: x-small; vertical-align: text-bottom; color: white;">
21                           <img align="top" src="img_gks/ou_logo_global40.gif" style="margin: 5px;" /><br />
22                           GKD Guest User
23                           <br />
24                           @ houic-s-604</div>
25                         
26                       <asp:Menu ID="Menu_Left" runat="server" CssClass="topMenu" Height="40px" ItemWrap="True" StaticEnableDefaultPopOutImage="False" DataSourceID="SiteMapDataSourceGKD2" Width="100%" MaximumDynamicDisplayLevels="0" OnMenuItemClick="Menu_Left_MenuItemClick">
27                           <StaticMenuItemStyle BorderStyle="Outset" BorderWidth="1px" Height="40px" BackColor="#D7E1F6" HorizontalPadding="10px" />
28                           <StaticSelectedStyle BackColor="#336699" BorderStyle="Inset" Font-Bold="True" ForeColor="White" BorderWidth="1px" />
29                           <DataBindings>
30                               <asp:MenuItemBinding DataMember="SiteMapNode" TextField="Title" />
31                           </DataBindings>
32                           <Items>
33                               <asp:MenuItem Text="My GKD" Value="My GKD"></asp:MenuItem>
34                               <asp:MenuItem Text="Administration" Value="Administration"></asp:MenuItem>
35                               <asp:MenuItem Text="Browse Database" Value="Browse Database"></asp:MenuItem>
36                               <asp:MenuItem Text="Logout" Value="Logout"></asp:MenuItem>
37                           </Items>
38                           <StaticHoverStyle BackColor="#E0E0E0" BorderStyle="Inset" Height="40px" ForeColor="Black" />
39                       </asp:Menu>
40                   </td>
41                   <td colspan="2" style="vertical-align:top; width: 100%;">
42   <div style="background-color: #e7efff; border-bottom: #d7e1f6 1px solid;">
43   <img src="img_gks/tmenu_square_fade.gif" align="right" /><asp:Menu ID="Menu_Top" runat="server" CssClass="topMenu" ItemWrap="True" StaticEnableDefaultPopOutImage="False" DataSourceID="SiteMapDataSourceGKD" MaximumDynamicDisplayLevels="0" OnMenuItemClick="Menu_Top_MenuItemClick" Orientation="Horizontal">
44       <StaticMenuItemStyle BorderStyle="Outset" BorderWidth="1px" Height="40px" BackColor="#D7E1F6" HorizontalPadding="10px" />
45       <StaticSelectedStyle BackColor="#336699" BorderStyle="Inset" Font-Bold="True" ForeColor="White" BorderWidth="1px" />
46       <DataBindings>
47           <asp:MenuItemBinding DataMember="SiteMapNode" TextField="Title" />
48       </DataBindings>
49       <Items>
50           <asp:MenuItem Text="My GKD" Value="My GKD"></asp:MenuItem>
51           <asp:MenuItem Text="Administration" Value="Administration"></asp:MenuItem>
52           <asp:MenuItem Text="Browse Database" Value="Browse Database"></asp:MenuItem>
53           <asp:MenuItem Text="Logout" Value="Logout"></asp:MenuItem>
54       </Items>
55       <StaticHoverStyle BackColor="#E0E0E0" BorderStyle="Inset" Height="40px" ForeColor="Black" />
56   </asp:Menu>
57   </div>
58                       <asp:ContentPlaceHolder runat="server" ID="contentPlaceHolder">
59                           </asp:ContentPlaceHolder></td>
60               </tr>
61           </table>
62           <asp:SiteMapDataSource ID="SiteMapDataSourceGKD" runat="server" ShowStartingNode="False" />
63           <asp:SiteMapDataSource ID="SiteMapDataSourceGKD2" runat="server" ShowStartingNode="False"
64               StartingNodeOffset="-1" StartingNodeUrl="~/Default.aspx" />
65       </form>
66   </body>
67   </html>
68   

 

Default.aspx

1 <%@ Page MasterPageFile="~/MasterPage.master" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2 hello world

 
Amanda Wang - M
Asp.Net User
Re: Controlling ASP.NET Menus Programmatically (how to programatically navigate from a menu?)7/27/2007 3:56:25 AM

0/0

Hi,

I think there is a litte difference between your requeirment and this article content.

I this article: It talks how to program the ASP.NET Menu control and create two menus bound to the same Web.sitemap file that work together, and the content of the second menu is determined by which menu item is selected in the first menu.

But, as your description,  your second menu's content is not determined by the first menu, so i think you don't need  to refer to the article completely.

You can make your menus bound to the same Web.sitemap file together, the codebehind of the menuitemclick is not necessary.

Below is a simple:

<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" MaximumDynamicDisplayLevels="0"
            OnMenuItemClick="Menu1_MenuItemClick" Orientation="Horizontal">
            <DataBindings>
                <asp:MenuItemBinding DataMember="SiteMapNode" TextField="Title" />
            </DataBindings>
        </asp:Menu>
    
    </div>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
        <asp:Menu ID="Menu2" runat="server" DataSourceID="SiteMapDataSource2" Orientation="Horizontal">
        </asp:Menu>
        <asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" ShowStartingNode="False"
            StartingNodeOffset="-1" />

hope it helps.


Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Yours sincerely,
Amanda Wang
Microsoft Online Community Support
jleviaguirre
Asp.Net User
Re: Controlling ASP.NET Menus Programmatically (how to programatically navigate from a menu?)7/27/2007 10:02:34 PM

0/0

Hi Amanda,

 My second menu is dependent on the first one. That's why I follow the article. What I can't figure out is how to set and retreive the values for the second menu.

 Right now I am in a point where I modified the web.sitemap because I want to dynamically load a control when the user clicks on the second menu. For that I coded the page_load event in myPage.aspx:

  

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ContentPlaceHolder cph = this.Master.FindControl("ContentPlaceHolderMain") as ContentPlaceHolder;
        SiteMapDataSource smds = this.Master.FindControl("SiteMapDataSourceGKD2") as SiteMapDataSource;
        Menu m = this.Master.FindControl("Menu_left") as Menu;

        string ctrlUrl = m.SelectedValue;
        cph.Controls.Add(new LiteralControl(ctrlUrl));
        //UserControl uc = this.LoadControl(smds.currentNode) as UserControl;
        //cph.Controls.Add(uc);
    }
        
 }

It works fine if I uncomment last two lines and hardcode the loadControl parameter but I don't know how to get the m.selectedItem.url or even the SiteMap.CurrentNode.Url because it's null. Is there a way to synchronize the sitemap and teh menu so I can get the url, value, tooltip or even description from the web.sitemap or m.selectedItem?

Amanda Wang - M
Asp.Net User
Re: Controlling ASP.NET Menus Programmatically (how to programatically navigate from a menu?)7/30/2007 3:23:01 AM

0/0

Hi,

I think you need you to make your second menu and the SiteMapPath point to the same SiteMap File, so you can config them in the Web.config:

for Example:

1. Web.config (config the SiteMap's providers):

   <siteMap>
      
<providers>
        
<add siteMapFile="~/App_Data/Job.sitemap" name="JobXmlSiteMapProvider"
            type
="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      
</providers>
    
</siteMap>
2. aspx file (specify the SiteMapProvoder for the SiteMapPath):
<asp:SiteMapPath ID="jobSiteMapPath" runat="server" PathSeparator=" ? " SiteMapProvider="JobXmlSiteMapProvider"></asp:SiteMapPath>

 3. cs code (The second menu's datasource is SitemapDataSource, you can specify the SiteMapProvoder for the second menu):

 this.SiteMapDataSource1.Provider =  SiteMap.Providers["JobXmlSiteMapProvider"];
Hope it can help you!

Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Yours sincerely,
Amanda Wang
Microsoft Online Community Support
jleviaguirre
Asp.Net User
Re: Controlling ASP.NET Menus Programmatically (how to programatically navigate from a menu?)7/30/2007 8:30:37 PM

0/0

Found the problem!

I did not follow EXACTLY the instructions on the article. I just did a copy +  paste from the first menu to the other and forgot to remove the databindings tag in the second menu. In other words, i removed the following lines and it worked:

29                           <DataBindings>
30                               <asp:MenuItemBinding DataMember="SiteMapNode" TextField="Title" />
31                           </DataBindings>

 Your help was helpful anyways. Thanks a lot.

 J

jleviaguirre
Asp.Net User
Re: Controlling ASP.NET Menus Programmatically (how to programatically navigate from a menu?)8/23/2007 4:44:47 PM

0/0

Check out this post http://forums.asp.net/p/1143593/1873682.aspx#1873682 dated same as this one. It is a simple solution for the original problem without almost any code behind.

6 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
ASP.NET 2.0 Black Book: black book Authors: Dreamtech Software, Dreamtech Software, Charul Shukla, Anil Kumar Barnwal, Dreamtech Software India, Pages: 1167, Published: 2006
Professional ASP.NET 2.0 Authors: Bill Evjen, Scott Hanselman, Farhan Muhammad, Srinivasa Sivakumar, Devin Rader, Pages: 1253, Published: 2005
Learning ASP.NET 3.5 Authors: Jesse Liberty, Dan Hurwitz, Brian MacDonald, Pages: 576, Published: 2008
Pro ASP.NET 2.0 in VB 2005: From Professional to Expert Authors: Laurence Moroney, Matthew MacDonald, Pages: 1253, Published: 2006
Professional ASP.NET 3.5: In C# and VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1673, Published: 2008
Pro ASP.NET 2.0 in C# 2005: Create Next-generation Web Applications with the Latest Version of Microsoft's Revolutionary Technology Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1426, Published: 2006
Professional ASP.NET 2.0 Databases Authors: Thiru Thangarathinam, Pages: 504, Published: 2007
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Beginning ASP.NET 3.5: In C# and VB Authors: Imar Spaanjaars, Pages: 734, Published: 2008
Beginning ASP.NET 2.0 in C# 2005: From Novice to Professional Authors: Matthew MacDonald, Pages: 1148, Published: 2006

Web:
Walkthrough: Controlling ASP.NET Menus Programmatically NET T:System.Web.UI.WebControls.Menu control programmatically by coordinating ... Learn more about site navigation. For more information, see ASP.NET Site ...
Walkthrough: Controlling ASP.NET Menus Programmatically NET Menu control programmatically by coordinating two menus on the same page ... Learn more about site navigation. For more information, see ASP.NET Site ...
Controlling ASP.NET Menus Programmatically (how to programatically ... Controlling ASP.NET Menus Programmatically (how to programatically navigate from a menu?) Last post 08-23-2007 12:44 PM by jleviaguirre. ...
Programmatically set the selected menu item in the Menu control ... Programmatically set the selected menu item in the Menu control ... NET: ASP.NET MVC Tip #29 – Build a Controller to Debug Your Custom Routes. Channel 8 ...
Loading a Menu Programmatically based on Roles - Creating a Custom ... ASP.NET Web Application Development with SQL Database connectivity. ... Step 17: Loading a Menu Programmatically based on Roles. Step 18: Our Default page. ...
Programmatically creating a menu - Infragistics Forums Am I missing something when programmatically creating a menu? Thanks, ... Rumen Stankov (MCSD.NET) The Infragistics ASP.NET Team ...
ASP.NET’s Menu control offers another site map navigation option ... Aug 21, 2007 ... Elements may be defined in a data source or programmatically added to the ... The following ASP.NET master page includes a Menu control, ...
Dotnet-Friends.com | Website Navigation or Menu with ... Jul 5, 2007 ... How to add a Navigation bar or a Menu to your Website? .... Walkthrough: Controlling ASP.NET Menus Programmatically ...
ASP.NET.4GuysFromRolla.com: Examining ASP.NET 2.0's Site ... Mar 8, 2006 ... The site navigation features in ASP.NET 2.0 make it easy to define a .... The TreeView and Menu control then programmatically recurse this ...
HOW TO: Programmatically customize site navigation in MOSS 2007 ... This object allows developers to programmatically control the navigation of a ... The QuickLaunch navigation menu may also be accessed programmatically. ...




Search This Site:










module naming scheme [dotnetnuke 4.0.0]

dnn 3.0.9 can't add webusercontrol to project

errors in the installation instructions?

obj directory

single sign-on and active directory

bi-polar dnn question

is there a way to stop vs.net from changing my ids on duplicate elements

child tabs?

issue installing on 1and1 hosting

bug: annoying effect of tabs recoding for links

to solicit about export data from sql to file .doc?

error in core blog module

html/text module

xmldsig & x.509 in .net 1.x

system.unauthorized.access.exception when call excel application

built in roles not working in code

session variable

i have to protect-filter stored procedures parameters?

bonosoft multipage 3.0 upgrade problems

cookie monster

do new asp.net 2.0 features require sql server 2005?

upgrading to a master page?!

pa edit module problem

continuosly logged out

currently verifiying userid/password from my db and then storing session( , is membership/profile a better approach, but i'm really confused., please help

ipostbackdatahandler

using javascript calendar in content page

find directory permissions with system.directoryservices

formatting & intellisense

can we add an enent handler to a button in a web user control

 
All Times Are GMT