Home All Groups Group Topic Archive Search About

menu control StaticSelectedStyle

Author
15 Feb 2007 9:13 PM
Jerry C
I am trying to setup a asp:menu control and have the selected item chang to
red.

The menu is in a user control and the menu items are added dynamically with
the lines

Dim FMItem As New MenuItem
FMItem.Text = "Some Text"
FMItem.Value = 3   'any number
  FMItem.Selectable = True
   Menu1.Items.Add(FMItem)


This code is in a loop to add several menuitems depending on the data

I set the StaticSelectedStyle like this

Menu1.StaticSelectedStyle.ForeColor = Drawing.Color.Red
Menu1.StaticSelectedStyle.BackColor = Drawing.Color.Red

The menu works great but the color of the selected menu item does not change
How does this work

Thank you

--
Jerry

Author
16 Feb 2007 2:07 AM
Walter Wang [MSFT]
Hi Jerry,

The StaticSelectedStyle is effective when a MenuItem is Selected, if you
set a MenuItem.Selected = True, you will see the style applied to it.

You could also try:

Menu1.StaticHoverStyle.BackColor = Drawing.Color.Red

Which will dynamically change a MenuItem's backcolor to Red when the mouse
cursor is over it.

Normally a Menu control will be bound to a sitemap file, which will
automatically set which MenuItem is selected when bound. Since you're not
using a data source, you're adding MenuItems manually, you will have to set
which MenuItem is selected by yourself; otherwise no MenuItem is selected
and the style you've set "seems not working".

Hope this helps.

Regards,
Walter Wang (waw***@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.
Author
16 Feb 2007 2:57 PM
Jerry C
Walter.

It seems I left a lot of information out about this problem. The
StaticSelectedStyle works just as  you posted Think you.

But:
This is inside of a user control.
The menu control is outside of a AJAX update panel and it is a trigger for
the panel so the partial update of the panel works but the menu control does
not update so the style cannot get set. I also connot put the Menu control in
the update panel because of java script errors also the docs for AJAX say
that I connot use a menu in a panel.

Here is the code:

<asp:Menu
        ID="Menu1"
        Width="168px"
        runat=server
        Orientation="Horizontal"
        StaticEnableDefaultPopOutImage="False"
        OnMenuItemClick="Menu1_MenuItemClick">
        <Items>
         <asp:MenuItem ImageUrl="6images/unselectedtab.GIF"
                      Text=" " Value="2" ></asp:MenuItem>
        </Items>
</asp:Menu>

  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
                <asp:MultiView ID="MVAttributes" runat="server">
        </asp:MultiView>
    </ContentTemplate>
    <Triggers>
     <asp:AsyncPostBackTrigger ControlID="Menu1" EventName="MenuItemClick" />
     </Triggers>
</asp:UpdatePanel>       



Thank you,

--
Jerry


Show quote
"Walter Wang [MSFT]" wrote:

> Hi Jerry,
>
> The StaticSelectedStyle is effective when a MenuItem is Selected, if you
> set a MenuItem.Selected = True, you will see the style applied to it.
>
> You could also try:
>
> Menu1.StaticHoverStyle.BackColor = Drawing.Color.Red
>
> Which will dynamically change a MenuItem's backcolor to Red when the mouse
> cursor is over it.
>
> Normally a Menu control will be bound to a sitemap file, which will
> automatically set which MenuItem is selected when bound. Since you're not
> using a data source, you're adding MenuItems manually, you will have to set
> which MenuItem is selected by yourself; otherwise no MenuItem is selected
> and the style you've set "seems not working".
>
> Hope this helps.
>
> Regards,
> Walter Wang (waw***@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.
>
>
Author
20 Feb 2007 3:44 AM
Walter Wang [MSFT]
Hi Jerry,

Thank you for detailed explanation.

Unfortunately, the Menu control is not going to work correctly if placed
inside the ASP.NET AJAX UpdatePanel currently:

===============
#ASP.NET Forums - What's up with UpdatePanels and how come nothing works?
Or: A brief explanation of how UpdatePanel works by the guy who wrote the
feature. (Long!)
http://forums.asp.net/thread/1440058.aspx

We have updated versions of the ASP.NET 2.0 validators that are tag-mapped
to the old versions (this means that if you have an
<asp:RequiredFieldValidator> tag it will use the updated one and not the
old one. These updated validators use the new registration APIs.


Other controls, such as WebParts, TreeView, and Menu were not updated to
use the new registration APIs primarily due to time constraints. We felt
that it was far less common to have these controls inside UpdatePanels
compared to the validators. The TreeView control has built-in AJAX
functionality anyway. In a future version of Atlas or ASP.NET we will have
updated versions of these controls, however.
===============

We're sorry for the inconvenience caused. Please feel free to let me know
(or email me directly) if you have any concerns regarding this issue. Thank
you for your understanding.


Regards,
Walter Wang (waw***@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.

AddThis Social Bookmark Button