473,490 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Menu Control - current node

AG
Using the new ASP.NET 2.0 menu control on a master page.
Is there any way to NOT have the current page be a live link and ideally
also have it appear in a different style?

Similar to the sitemappath control's RenderCurrentNodeAsLink property.

TIA

--

AG
Email: discuss at adhdata dot com


Sep 19 '06 #1
10 2157
"AG" <NO**********@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Using the new ASP.NET 2.0 menu control on a master page.
Is there any way to NOT have the current page be a live link and ideally
also have it appear in a different style?

Similar to the sitemappath control's RenderCurrentNodeAsLink property.
I don't think it's possible just with the <asp:Menu>'s properties.

Dead easy in code, though...
Sep 19 '06 #2
AG
Care to give a hint?

--

AG
Email: discuss at adhdata dot com

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:en**************@TK2MSFTNGP03.phx.gbl...
"AG" <NO**********@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Using the new ASP.NET 2.0 menu control on a master page.
Is there any way to NOT have the current page be a live link and ideally
also have it appear in a different style?

Similar to the sitemappath control's RenderCurrentNodeAsLink property.

I don't think it's possible just with the <asp:Menu>'s properties.

Dead easy in code, though...

Sep 20 '06 #3
Hi AG,

If you are using DataBinding on the Menu control, you can handle it's
DataBound event and change current item:

protected void Menu1_DataBound(object sender, EventArgs e)
{
if (Menu1.SelectedItem.NavigateUrl == Request.Path)
{
Menu1.SelectedItem.Selectable = false;
}
}

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 20 '06 #4
AG
Thanks for the reply Walter.
That did not work. It generated an exception 'object reference not set to
instance of object'.

However, you got me on the right track.
The following did work:

Protected Sub Menu1_MenuItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.MenuEventArgs) Handles mnuTop.MenuItemDataBound
If e.Item.NavigateUrl = Request.Path Then
e.Item.Selectable = False
End If
End Sub

--

AG
Email: discuss at adhdata dot com

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:ii*************@TK2MSFTNGXA01.phx.gbl...
Hi AG,

If you are using DataBinding on the Menu control, you can handle it's
DataBound event and change current item:

protected void Menu1_DataBound(object sender, EventArgs e)
{
if (Menu1.SelectedItem.NavigateUrl == Request.Path)
{
Menu1.SelectedItem.Selectable = false;
}
}

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 20 '06 #5
Hi AG,

Thanks for the correctness.

I forgot to check for null reference on Menu1.SelectedItem:

if (Menu1.SelectedItem != null && Menu1.SelectedItem.NavigateUrl ==
Request.Path)

Your code works, however, please note: MenuItemDataBound event will be
fired for every menu item in your menu control; while DataBound event will
be fired only once for the menu control. So I still recommend you do this
in the DataBound event.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 20 '06 #6
AG
Thanks Walter.

I understand what you are saying and it does work providing the user arrived
at the page by clicking on that particular menu.
If user arrived by any other means, like another menu control, sitemappath,
sitemap or any other link, then the menu link for the current page is still
active.

--

AG
Email: discuss at adhdata dot com

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:fW**************@TK2MSFTNGXA01.phx.gbl...
Hi AG,

Thanks for the correctness.

I forgot to check for null reference on Menu1.SelectedItem:

if (Menu1.SelectedItem != null && Menu1.SelectedItem.NavigateUrl ==
Request.Path)

Your code works, however, please note: MenuItemDataBound event will be
fired for every menu item in your menu control; while DataBound event will
be fired only once for the menu control. So I still recommend you do this
in the DataBound event.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 20 '06 #7
When the navigation is made by another controls, we need to recursively
walk the Menu's items and determine which item's NavigateUrl is equal to
current URL:

protected void Menu1_DataBound(object sender, EventArgs e)
{
UnselectCurrentMenuItem(Menu1.Items);
}

private bool UnselectCurrentMenuItem(MenuItemCollection
menuItemCollection)
{
foreach (MenuItem mi in menuItemCollection)
{
if (mi.NavigateUrl == Request.Path)
{
mi.Selectable = false;
return true;
}
if (UnselectCurrentMenuItem(mi.ChildItems))
return true;
}
return false;
}

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 22 '06 #8
AG
Thanks Walter.

This method accomplishes the same end result as mine.
What are the advantages/disadvantages of each method?

--

AG
Email: discuss at adhdata dot com

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:xQ*************@TK2MSFTNGXA01.phx.gbl...
When the navigation is made by another controls, we need to recursively
walk the Menu's items and determine which item's NavigateUrl is equal to
current URL:

protected void Menu1_DataBound(object sender, EventArgs e)
{
UnselectCurrentMenuItem(Menu1.Items);
}

private bool UnselectCurrentMenuItem(MenuItemCollection
menuItemCollection)
{
foreach (MenuItem mi in menuItemCollection)
{
if (mi.NavigateUrl == Request.Path)
{
mi.Selectable = false;
return true;
}
if (UnselectCurrentMenuItem(mi.ChildItems))
return true;
}
return false;
}

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 22 '06 #9
Hi AG,

After doing more research, actually your way handling in the ItemDataBound
event is the best one, because multiple MenuItem may have the same
NavigateUrl. My approach will not handle this situation correctly. Sorry
for my mistake.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 25 '06 #10
AG
Thank you!

--

AG
Email: discuss at adhdata dot com

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:3i**************@TK2MSFTNGXA01.phx.gbl...
Hi AG,

After doing more research, actually your way handling in the ItemDataBound
event is the best one, because multiple MenuItem may have the same
NavigateUrl. My approach will not handle this situation correctly. Sorry
for my mistake.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 26 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2545
by: hemanth.singamsetty | last post by:
Hello there, I've a drop down menu (created using CSS & Javascript -- see code below). My problem is, whenever I click a link on the menu the new page replaces the current page (and the menu...
5
5464
by: Dean L. Howen | last post by:
Dear friends, Could we determine when context menu should appear?
0
1377
by: Phl | last post by:
hi, does any know why my javascript dropdownlist in my user control will only appear if I have my code as follows: // create an instance of the user control Control UCAdminDDMenu =...
4
2645
by: Mark Parter | last post by:
I have a master page which contains a Menu control and a SiteMapPath control, both are bound to the same web.sitemap XML file. Say I have 2 pages, Page 1 and Page 2. Now Page 2 can only be accessed...
1
2691
by: Chris Murphy via DotNetMonster.com | last post by:
Hi all, I'm just wondering if any one can help me with this development issue I'm having. I've created a customized treeview control to handle the particular tasks to which I'll be using it. Within...
2
4898
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
0
798
by: Martin | last post by:
Hi, I want to get the following navigation effect. Can I do it with the new Menu control? Say I have a menu hierarchy like 1 1.1 1.2 1.3
2
3710
by: Claire | last post by:
I've a treeview control containing a root node with several children on a windows form. I select a node with a left mouse button click. I then select one of the other nodes with right mouse click...
0
3272
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.