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 > microsoft_downloads.css_friendly_control_adapters Tags:
Item Type: NewsGroup Date Entered: 5/12/2006 3:20:10 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 15 Views: 36 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
16 Items, 1 Pages 1 |< << Go >> >|
mtait
Asp.Net User
Background of currently selected page5/12/2006 3:20:10 PM

0/0

Hi - using the CSS adapters, is there anyway to set the CSS for the currently selected page in the menu item? (ie. have the background a different color)

Thanks, Mark
Russ Helfand
Asp.Net User
Re: Background of currently selected page5/12/2006 4:45:36 PM

0/0

The MenuAdapter doesn't currently mark the menu node that corresponds to the currently requested page.  That's an interesting feature.  Would you suggest that it be added to a future version of this sample kit?

In detail... I'm suggesting that the adapter could compare the menu node's URL against HttpContext.Current.Response.Url.  If the two match the adapter would add a class like AspNet-Menu-CurrentPage to the <li> corresponding to that menu node. The menu node's URL is item.NavigateUrl in the existing method CSSFriendly.MenuAdapter.BuildItem.

What are your thoughts? Is this something you'd like to try on your own... maybe you could post some code if you got something to work as you wanted.  Otherwise, let me know and I'll add it my to-do list so it can be considered for a future rev of the kit.


Russ Helfand
Groovybits.com
mtait
Asp.Net User
Re: Background of currently selected page5/12/2006 7:43:20 PM

0/0

Hi Russ - I've only just downloaded it, but I'll see if I can igure out how it works.

Kind regards,

Mark
bttrflii
Asp.Net User
Re: Background of currently selected page5/12/2006 9:49:57 PM

0/0

russ -
this is along the same lines as i was asking about.  actually, the treeview is already supposed to have code that highlights the current menu item and it even has both a "ParentNodeStyle-CssClass" and "SelectedNodeStyle-CssClass" in place.  since the css adapter broke this functionality of the treeview, i created code that would add the selected css class back to the node path after nobody else seemed to know how.  i posted my modified treeview file in my final reply to my own thread at http://forums.asp.net/thread/1277876.aspx .  i'm glad someone else was able to say it in words that popped in your mind, because this was a very big frustration of mine when switching to the adapter.

mtait -
if the code i came up with helps you at all and you expand on it, i'd love to see what you come up with.  c# isn't my forte.  :)  note that my solution doesn't add the ParentNodeStyle-CssClass like the non-adapted treeview does, but it does add the SelectedNodeStyle-CssClass class to the selected node *and* all of that node's relatives going up the tree towards to the root.

~ cj
Russ Helfand
Asp.Net User
Re: Background of currently selected page5/12/2006 10:06:56 PM

0/0

Got it.  It's definitely on my radar screen for the next rev.
Russ Helfand
Groovybits.com
Shakhan
Asp.Net User
Re: Background of currently selected page7/12/2006 3:03:45 PM

0/0

Hi !

Anything new since 05-13-2006 ??

Nobody highlights the selected menuItem for the moment??  

Russ Helfand
Asp.Net User
Re: Background of currently selected page7/12/2006 7:27:51 PM

0/0

I've given this problem some thought.  Here's where I'm at so far...

First, I think we need to agree that the "selected" menu item is the MenuItem in the Menu whose Selected property is set to true.  This re-uses the existing .Net framework mechanism to "flag" the selected item.  It is up to you to have logic to actually set this "flag" on one of your menu items.

With that in mind, I've created the following test page:

<%@ Page Language="C#" StylesheetTheme="Basic" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
  {
    // Display the text of the menu item selected by the user.
    Message.Text = "You selected " +
      e.Item.Text + ".";
    e.Item.Selected = true;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<!--[if lt IE 9]>
    <link runat="server" rel="stylesheet" href="~/BrowserSpecificCSS/IEMenu.css" type="text/css" id="IEMenuCSS" />
<![endif]-->
<style>
.AspNet-Menu-Selected
{
    background: yellow !important;
}
.AspNet-Menu-ChildSelected
{
    background: red !important;
}
.AspNet-Menu-ParentSelected
{
    background: green !important;
}
</style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="SampleMenu">
      <asp:menu id="NavigationMenu" onmenuitemclick="NavigationMenu_MenuItemClick" runat="server" CssSelectorClass="PrettyMenu">     
        <items>
          <asp:menuitem text="Home">
            <asp:menuitem text="Music">
              <asp:menuitem text="Classical" />
              <asp:menuitem text="Rock" />
              <asp:menuitem text="Jazz" />
            </asp:menuitem>
            <asp:menuitem text="Movies" Selectable="false">
              <asp:menuitem text="Action" />
              <asp:menuitem text="Drama" />
              <asp:menuitem text="Musical" />
            </asp:menuitem>
          </asp:menuitem>
        </items>
      </asp:menu>   
    </div>
   
    <asp:label id="Message" runat="server"/>
   
    </form>
</body>
</html>

You should be able to create a new web site (once you've installed the adapter kit's VSI), create a subfolder called Test in the root of this test web site and then place the markup shown above in a file called testMenu.aspx.

Before running this test page, though, you need to modify your menu adapter code per the instructions found here:

http://forums.asp.net/post/1295051.aspx (or view the full thread by clicking the "view complete thread" link at the top/left)

This enhances the beta 1.1 version of the menu so it can handle menus that are intended to postback to the same page (like our test page does).

Can you confirm that this test page seems to run?

If you get that far, then you are in good shape.  Notice that this test page puts together a simple menu and that the page has some "extra" styles that indicate how to render the selected MenuItem (and its parent or child items).  Of course, our adapter isn't (yet) fancy enough to render markup that uses these helpful (new) styles... so we need to enhance it.

In http://forums.asp.net/post/1295051.aspx you'll notice this line:

writer.WriteAttribute("class", "AspNet-Menu-Link");

There is a similar line in the "else" for the "if" that sets the class to "AspNet-Menu-NonLink."  Change both of these lines so they look like this:

writer.WriteAttribute("class", GetItemClass(menu, item));

Finally, add these new methods to the MenuAdapter class:

        private string GetItemClass(Menu menu, MenuItem item)
        {
            string value = "AspNet-Menu-NonLink";
            if (item != null)
            {
                if (((item.Depth < menu.StaticDisplayLevels) && (menu.StaticItemTemplate != null)) ||
                    ((item.Depth >= menu.StaticDisplayLevels) && (menu.DynamicItemTemplate != null)))
                {
                    value = "AspNet-Menu-Template";
                }
                else if ((item.NavigateUrl.Length > 0) || item.Selectable)
                {
                    value =  "AspNet-Menu-Link";
                }

                if (item.Selected)
                {
                    value += " AspNet-Menu-Selected";
                }
                else if (IsChildItemSelected(item))
                {
                    value += " AspNet-Menu-ChildSelected";
                }
                else if (IsParentItemSelected(item))
                {
                    value += " AspNet-Menu-ParentSelected";
                }
            }
            return value;
        }

        private bool IsChildItemSelected(MenuItem item)
        {
            bool bRet = false;

            if ((item != null) && (item.ChildItems != null))
            {
                bRet = IsChildItemSelected(item.ChildItems);
            }

            return bRet;
        }

        private bool IsChildItemSelected(MenuItemCollection items)
        {
            bool bRet = false;

            if (items != null)
            {
                foreach (MenuItem item in items)
                {
                    if (item.Selected)
                    {
                        bRet = true;
                        break;
                    }
                    bRet = IsChildItemSelected(item.ChildItems);
                }
            }

            return bRet;
        }

        private bool IsParentItemSelected(MenuItem item)
        {
            bool bRet = false;

            if ((item != null) && (item.Parent != null))
            {
                if (item.Parent.Selected)
                {
                    bRet = true;
                }
                else
                {
                    bRet = IsParentItemSelected(item.Parent);
                }
            }

            return bRet;
        }

Now try using the test page.  Select an item and you'll see its background change color.  Look at the background of the parent/children of the selected menu item.  They should be shown with distinct background colors, too.  Do you see that?

Remember that you can also choose a "selected" menu item when the page is first loaded by using the Selected attribute in the MenuItem tag or by heuristically deciding on a menu item to mark as selected in the page's Page_Load method, etc.

Good luck with this.  I hope you get all the way through these instructions.  If you run into problems, let us know.  I'll try to help out again (sooner this time!).

Keep in mind that when we release a new rev of the kit it will have this fix so you won't have to suffer this pain forever.


Russ Helfand
Groovybits.com
Shakhan
Asp.Net User
Re: Background of currently selected page7/13/2006 10:38:30 AM

0/0

Hi Russ ! Thanks for this code I was looking for :-)

May be this time I can help, as far as I know, this code just highlight the parentItem of the selected item...

This is how I modified (just a little) the private bool IsChildItemSelected(MenuItemCollection items)  to highlight all the parentItems:

 private bool IsChildItemSelected(MenuItemCollection items)
        {
            bool bRet = false;
            if (items != null)
            {
                foreach (MenuItem item in items)
                {
                    if (item.Selected) { bRet = true;
                        break;
                    }
                    if (IsChildItemSelected(item.ChildItems))
                        return true;
                }
            }
            return bRet;
        }

 Hope this help...
Russ Helfand
Asp.Net User
Re: Background of currently selected page7/13/2006 5:25:17 PM

0/0

Hi Shakhan, I'm glad the code posted earlier was helpful.

I appreciate that you alerted me to the fact that there was a logic error.  You are absolutely correct: whenever the inner call to IsChildItemSelected(item.ChildItems) is made, it should break out of the foreach and return true, just like what happens if item.Selected is true.

I ended up with code like this:

        private bool IsChildItemSelected(MenuItemCollection items)
        {
            bool bRet = false;

            if (items != null)
            {
                foreach (MenuItem item in items)
                {
                    if (item.Selected || IsChildItemSelected(item.ChildItems))
                    {
                        bRet = true;
                        break;
                    }
                }
            }

            return bRet;
        }

What do you think? One advantage is that it has just a single "return" statement... which some people consider generally a good thing.


Russ Helfand
Groovybits.com
Shakhan
Asp.Net User
Re: Background of currently selected page7/19/2006 9:40:57 AM

0/0

Yeah! you're right, your code is better !!

You're the boss, keep up the good work :-)

Rodrigo Gagliar
Asp.Net User
Re: Background of currently selected page7/30/2006 8:11:24 PM

0/0

Hi there,

I?m trying to use this feature with MasterPages.

When I put the menu into the content page, it works fine.

When I put it into the master page don?t work.
Could you help me to understant a way to put it to work.

Below is the master page source code.

Thanks a lot,
Rodrigo Gagliardi

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="HomePage.master.cs" Inherits="HomePage" %>

<%@ Register TagPrefix="wilco" Namespace="Wilco.Web.SyntaxHighlighting" Assembly="Wilco.SyntaxHighlighter" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server">

<title>Untitled Page</title>

<link href="App_Themes/Basic/MenuStyle.css" rel="stylesheet" type="text/css" />

<

style runat="server">

.AspNet-Menu-Selected

{

background: yellow !important;

}

.AspNet-Menu-ChildSelected

{

background: red !important;

}

.AspNet-Menu-ParentSelected

{

background: green !important;

}

</

style>

<

script runat="server">

void Menu1_MenuItemClick(Object sender, MenuEventArgs e)

{

// Display the text of the menu item selected by the user.

Message.Text =

"You selected " +

e.Item.Text +

".";

e.Item.Selected =

true;

}

</

script>

</

head>

<

body bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0">

<form id="form1" runat="server">

<div>

<center>

<table cellpadding="0" cellspacing="0" border="0" width="100%" height="185" background="./Library/fundotop.png">

<tr>

<td valign="bottom">

<center>

&nbsp;<asp:label id="Message" runat="server"/>

<table cellpadding="0" cellspacing="0" border="0" width="776" height="37">

<tr>

<td valign="middle" height="37">

<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" SkinID="SampleMenuHorizontal" CssSelectorClass="MainMenu" Height="37" BorderStyle="None" BorderWidth="0px" OnMenuItemClick="Menu1_MenuItemClick">

<Items>

<asp:MenuItem Text="&lt;img src=1.gif width=50 border=0 height=2&gt;&lt;br&gt;Produtos &lt;br&gt;e Servi&#231;os" Value="Opcao 1" NavigateUrl="~/Default.aspx"></asp:MenuItem>

<asp:MenuItem Text="&lt;img src=1.gif width=50 border=0 height=9&gt;&lt;br&gt;Home" Value="Opcao 2" NavigateUrl="~/Default2.aspx"></asp:MenuItem>

<asp:MenuItem Text="&lt;img src=1.gif width=50 border=0 height=2&gt;&lt;br&gt;Not&#237;cias e Novidades" Value="Opcao 3" NavigateUrl="~/Default.aspx"></asp:MenuItem>

</Items>

</asp:Menu>

</td>

</tr>

</table>

</center>

</td>

</tr>

</table>

<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

</asp:contentplaceholder>

</center>

</div>

</form>

</

body>

</

html>
Rodrigo Gagliar
Asp.Net User
Re: Background of currently selected page7/30/2006 8:13:27 PM

0/0

Sorry, but the Forum?s editor broked the source code content, but it?s possible to understand.

Thanks a lot.
Russ Helfand
Asp.Net User
Re: Background of currently selected page7/31/2006 2:07:12 AM

0/0

Hi Rodrigo,

I'll be happy to lend a hand but I need a bit more detail about what exactly is not working.  Can you describe what you are seeing in the browser and what about it is wrong?  Remember that you'll need to declare what theme you are using by setting the Theme attribute in the @Page directive of the ASPX file that uses your new master page.  Have you done that?  Fundamentally, there is nothing that should prevent you from using adapted menus, treeviews, etc. from a master page.  They should work identically to the way they work in ASPX pages.  In fact, I know this is true because I've done it several times.  So, I'm guessing that there is something else that you're running into that is preventing things from working exactly right in your case.  I bet if we work together we can sort it out.  Maybe you can post the HTML being rendered into the browser and (very important) provide a description of what is wrong visually.


Russ Helfand
Groovybits.com
Rodrigo Gagliar
Asp.Net User
Re: Background of currently selected page8/1/2006 1:12:09 AM

0/0

Hi Russ,

Thanks a lot for your fast reply.
The menu works very well, using themes correctly. Now I just have two problems:

1. I don?t obtain the feature to mark (or keep) the menu option with a different color (or backgroud image) when I click on any option, using the menu into the masterpage. When I click a child I want that the principal option be hightlighted too.
    Don?t work in the menu on the masterpage, but when I put the menu at the Content page, this feature works.
    I tried to implement, but I saw debbuging that the NavigationMenu_MenuItemClick event don?t happens when I click the menu option.
   I?m trying to implement on http://rodrigogagliardi.hopto.org (some times this page don?t work, because my computer is off, but you can try to access). On this page the menu is on the masterpage and the feature don?t work.
  And you can open http://rodrigogagliardi.hopto.org/default2.aspx and see the menu into the content page working. Try to click on Home menu link.

2. The options are aligned verticaly using a <img> tag before text of the menu option. Do you know a attribute to vertical align?

3. The last thing is that I want to have the just the CSS Menu Style refered on the pages.

Thanks a lot for your help.
regs..

Rodrigo

 

Russ Helfand
Asp.Net User
Re: Background of currently selected page8/1/2006 4:58:35 PM

0/0

Regarding your earlier questions...

  1. I'm not sure why the server-side event for menu-click wouldn't work on a master page... but does work on a content page.  That's rather odd.  Have you tried temporarily getting rid of the adapters (by deleting your .browser file) to see if you can get this to work with the native implementation of the menu control?
  2. Vertical alignment in CSS can get tricky.  There are some earlier posting that include good links that discuss vertical alignment.  See, for example, http://forums.asp.net/thread/1320639.aspx.
  3. I'm not sure what you are asking in question #3.  Can you restate it in a different way?

Russ Helfand
Groovybits.com
Rodrigo Gagliar
Asp.Net User
Re: Background of currently selected page8/2/2006 2:44:01 AM

0/0

Thanks Russ.
If it is not an abuse of your patience, I?d like to ask you to take a look in 2 minutes at my little 143Kb code zipped at: http://rodrigogagliardi.hopto.org/site.zip

You can see the diferences in Default.aspx and  Default2.aspx. And the code implementation in MenuAdapter.cs.

About the 3# question, is that I?d like to have the Friendly CSS for the menu control. I perceived that I just need to delete the file from the Theme directory and it you not referenced automaticaly.

Thanks a lot again.

Rodrigo Gagliardi

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


Free Download:

Books:
How to Do Everything with Microsoft Office FrontPage 2003 Authors: David Plotkin, Pages: 464, Published: 2003
Dreamweaver CS3: The Missing Manual Authors: David Sawyer McFarland, Pages: 995, Published: 2007
Oracle HTML DB Handbook Authors: Lawrence C. Linnemeyer, Bradley D. Brown, Pages: 486, Published: 2006
Visio 2007 For Dummies Authors: John Paul Mueller, Debbie Walkowski, Pages: 387, Published: 2006
Microsoft FrontPage 2002 Unleashed Authors: William R. Stanek, David Berry, Duane Hellums, Mark Ray, Jinjer Simon, Pages: 1184, Published: 2002
Liskin's DBASE IV Programming Book: Programming Book Authors: Miriam Liskin, Pages: 1315, Published: 1990
How to Do Everything with FrontPage 2002: How to Do Everything With.. ... Authors: David Plotkin, Pages: 633, Published: 2001
The GIMP for Linux and Unix: for linux and unix Authors: Phyllis Davis, Pages: 306, Published: 2000
Web Design in a Nutshell: A Desktop Quick Reference Authors: Jennifer Niederst Robbins, Pages: 796, Published: 2006
Excel: The Missing Manual Authors: Matthew MacDonald, Pages: 770, Published: 2005

Web:
Background of currently selected page - ASP.NET Forums Hi - using the CSS adapters, is there anyway to set the CSS for the currently selected page in the menu item? (ie. have the background a ...
G128: Indicating current location within navigation bars ... In addition, the background color of the selected tab is changed from the ... the result of following this link is the Web page currently being displayed. ...
Background Settings - Theme Builder Plugin - Adaptavist.com Wiki This menu allows you to quickly customise the background colour and/or image of the currently selected panel. Why does this page say "DRAFT"? ...
(WO/2005/103875) TECHNIQUES FOR SIMULTANEOUSLY DISPLAYING A ... A user can minimize the content page, but the priority background page cannot .... is an array of contacts that are currently selected in the friends list. ...
Chapter 2A: Measuring Cancer Anorexia/Cachexia: A Case Study ... Currently selected section: Protocol Background · Protocol Goals · Patient Eligibility · Test Schedule · Stratification Factors ... Page 5 of 34. Next Page ...
Page Background Image Not Showing when Page Background Colour ... There are currently too many topics in this group that display first. ... Color selected you cannot see the page background image as the page ...
Web Page Background Color Evaluative Effect on Selected Product ... Web Page Background Color Evaluative Effect on Selected Product Attributes. Speaker:. Karen Biers Extension Specialist Utah State University ...
PixInsight LE Tutorial :: Dynamic Background Extraction in LE 1.0.2 The square graphic on the Current Sample tab page of the DBE window ... of background pixels that are being considered for the currently selected sample. ...
Keyboard Shortcuts « WordPress Codex Pressing k moves the current selection (light-blue background) up. Note that if you come to the bottom of a page of comments and press j again, ...
Microsoft Windows Vista, Choose the Desk top Background Click the Desktop Background link. The Desktop Background page appears. The page shows the current Windows wallpaper and the currently selected wallpaper ...

Videos:
The House of Wii It's the House dreams are made of. Admit it you wish you lived here don't you? Nintendo and their European marketing company Cake Media set up a "W...
how to get a channel background in 3 simpe steps #1 select a pic #2 upload to imagesh ack.u s (no spaces) and copy the direct image link at the bottom of page #3 go to ure channel and click "edit ...
The Metropolitan Museum of Art FIND THIS AND OVER 6,000 TRAVEL VIDEOS AT WWW.TRAVELVIDEOSTORE.COM America has one of the greatest museums in the world, but because it's such a vast...
blueEnergy - Renewable Energy in Nicaragua This short clip shows blueEnergy's energy project sites on the Caribbean Coast of Nicaragua. The audio portion is a radio spot developed by the Blue...
A Caribbean Tale - A VMK Mini Movie Submitted Into the VMKLand Second Movie Contest ( No Winner Ever Selected ). Produced,directed,and written by KingGolden Starring:CarnationPink,DinoD...
Nvu: Formatting Application: Nvu - Formatting pages and page content.
JonasBonusMusic Contest! This contest will NOT be canceled this time so get ready to enter! Prizes: 5th place...video made by them (of their choice) will be featured on our ...
how to make light sabers using gimp this is my first video so enjoy and it would be nice to see some of the pictures you make using this effect 1. open up gimp 2. open up a picture of ...
Craig Stone Magic Craig Stone - Premier Magical Entertainer. Studying the art of magic since the age of 12, Craig has been entertaining professionally for nearly two ...
Cisco Enterprise TV Video Data Sheet Cisco Enterprise TV is an interactive application that enables organizations to deliver on-demand video and broadcast live TV channels over an IP net...




Search This Site:










dnn error

vwd guided tour, first approach

tree/tabstrip/toolbar control how to use?

error event handling

steps to upgrade data acces from 1.10 to 2.12

search string

unable to select items within asp:table

redirect from portal alias to primary name

new install alias issue

mdse problem with commerce starter kit install

is 2.0 authentication worth the time?

question: file upload form - directly to a remote ftp server

safely removing 'standard' modules

force dnn to clear cache

getting an sql querry in an array

bug / issue tracking module

using com to display microsoft excel in internet explorer

accessing a page's profile from a wrapper class

asp.net 2.0 membership users not online?

remote debugger

double-click event for listbox?

ide hangs when switching from source to design view

cookies

vb and c# question

loading web user controls dynamically

gaining access to user data? is it possible?

no question too simple?

sql server express

databinding to calendar control

word object library

 
All Times Are GMT