Keep menu item open after click

8 posts, 0 answers
  1. Richard
    Richard avatar
    63 posts
    Member since:
    Apr 2008

    Posted 18 Dec 2009 Link to this post

    Can someone give me a hand:  I have a menu item that when clicked will be populated server-side with a sub-set of menu items.  When the user clicks the initial menu item, I'd like it to stay open after it is populated with the new items.

  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 22 Dec 2009 Link to this post

    Hi Richard,

    Here is a sample:

    <telerik:RadMenu ID="RadMenu1" Runat="server" onitemclick="RadMenu1_ItemClick">
        <Items>
            <telerik:RadMenuItem runat="server" Text="Root RadMenuItem1">
            </telerik:RadMenuItem>
        </Items>
    </telerik:RadMenu>
    <script type="text/javascript">
        function openFirstMenuItem() {
            var menu = $find("<%= RadMenu1.ClientID %>");
            var itemToOpen = menu.get_items().getItem(0);
            itemToOpen.open();
        }
    </script>

    protected void RadMenu1_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
    {
        e.Item.Items.Add(new RadMenuItem("child 1"));
        e.Item.Items.Add(new RadMenuItem("child 2"));
        string script = "Sys.Application.add_load(function(){ openFirstMenuItem(); });";
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "openmenu", script, true);
    }


    Greetings,
    Veskoni
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Richard
    Richard avatar
    63 posts
    Member since:
    Apr 2008

    Posted 22 Dec 2009 Link to this post

    Veskoni,

    Thanks for your reply and the sample code.  I tried to apply the code but found the menu didn't automatically open after I clicked the "Action" button.  I have to move my mouse back off of it then hover over it again.  By looking at your supplied code, it appears that it "should" stay open, but doesn't.

  4. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 25 Dec 2009 Link to this post

    Hello Richard,

    I have tried Veskoni's code in a sample project and it seem to work just as expected. Can you provide us with your implementation so we can see what is going wrong on your side. I have attached my test project as an attachment. Can you reproduce the problem on it?

    All the best,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. aster
    aster avatar
    5 posts
    Member since:
    Dec 2009

    Posted 28 Dec 2009 Link to this post

    Hi Genady,

    I am customizing the RadMenu control for our internal Sitefinity site, and I have a question regarding menu customization. The code with this example is partly what I am looking for, but I would like the sub menu items to stay even if the focus on them is out. They should disappear only when you click on root menu item.

    I am trying to accomplish what you have on your demo site, http://demos.telerik.com/aspnet-ajax/ajax/examples/overview/defaultcs.aspx. When you click on an element the child items stay and only when you click on their parent they collapse. Could you please tell me how I can accomplish that for the RadMenu.

    Thanks!
  6. T. Tsonev
    Admin
    T. Tsonev avatar
    2834 posts

    Posted 29 Dec 2009 Link to this post

    Hi,

    You can try the click-to-open mode of RadMenu. It is pretty close to what you describe. Please, see this example:

    http://demos.telerik.com/aspnet-ajax/menu/examples/default/defaultcs.aspx

    Check "ClickToOpen" to see this behavior.

    Kind regards,
    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Matteo Tognolo
    Matteo Tognolo avatar
    3 posts
    Member since:
    Feb 2010

    Posted 22 Jul 2010 Link to this post

    Hi,

    I fill a RadMenu dinamically by List<> of objects.
    I have set the navigateUrl property and I want, after the page is re-load, that the clicked item is selecetd.

    Is possible associate an ID attribute to the RadMenuItem? With Attributes collection?

    How can I do?

    Thanks in advanced.

    Matteo
  8. Yana
    Admin
    Yana avatar
    5030 posts

    Posted 28 Jul 2010 Link to this post

    Hi Matteo Tognolo,

    You should manually find the clicked menu item and selects it, this can be done in Page_Load event like this:

    RadMenuItem currentItem = RadMenu1.FindItemByUrl(Request.Url.PathAndQuery);

    This online example demonstrates similar approach.

    Here you can read how to work Attributes collection of RadMenuItem.

    Kind regards,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top