Click on item child of the radmenu

9 posts, 0 answers
  1. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 25 Jan 2013 Link to this post

    Hi,
    i've a radmenu and this code javascript for open the radwindow:
    <telerik:RadMenu ID="RadMenu1" Runat="server" EnableRoundedCorners="True"
    OnClientItemClicked="MenuOpenWindow"
    EnableShadows="True" Skin="Sunset" style="top: 0px; left: 0px">
    .....
    function MenuOpenWindow(sender, eventArgs) {
    if (eventArgs.get_item().get_text() == "Nuova immagine") {
    $find("<%= RadWindowLoadprofile.ClientID %>").show();
    return false;
    }
    }

    this code perfect function but when i click on item child, this item is selected instead I do not want this. How can I do?

    see the image

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jan 2013 Link to this post

    Hi,

    One suggestion is that you can attach OnClientItemClicking event of RadMenu and can cancel it as follows.

    ASPX:
    <telerik:RadMenu ID="RadMenu1" runat="server" OnClientItemClicking="MenuOpenWindow" >
        ..........
    </telerik:RadMenu>

    JS:
    <script type="text/javascript">
       function MenuOpenWindow(sender, eventArgs) {
            if (eventArgs.get_item().get_text() == "Nuova immagine") {
                $find("<%= RadWindowLoadprofile.ClientID %>").show();
                eventArgs.set_cancel(true);
            }
        }
    </script>

    Hope this helps.

    Regards,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 25 Jan 2013 Link to this post

    hi
    its good thanks you
  5. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 28 Jan 2013 Link to this post

    Sorry,
    another problem, now its possible show radwindow from radmenu into code behind? (vbnet)
    as with example javascript? and second into javascript function for the item that have the child,
    the code:
    eventArgs.set_cancel(true);

    must to function in the root node too.

    example:

    first item
    ......child_1
    ......child_2

    then the eventarge.set_cancel(true) must to function on first item but on child clicked too 
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2013 Link to this post

    Hi Fabio,

    Try the following code snippet which will do the same working as of the code given in JS
    VB:
    Protected Sub radMenu1_ItemClick(sender As Object, e As Telerik.Web.UI.RadMenuEventArgs)
        If e.Item.Text = "Nuova immagine" Then
            radMenu1.Items(0).Selected = False
        End If
    End Sub

    Thanks,
    Shinu.
  7. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 28 Jan 2013 Link to this post

    Perfect function!!!
    but if must to click on item child?
    in the event

    RadMenu1_ItemClick

    when i press on item child, this event no start, why? So i can't to intercept the code write into event

  8. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 29 Jan 2013 Link to this post

    Hello,

    Attaching that handler to the associated server-side event in the markup code would be necessary in order to fire that event and execute the provided code. You could do that using the following snippet:
    //markup code
    <telerik:RadMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick">
     .....       
    </telerik:RadMenu>
    //code behind
    Protected Sub RadMenu1_ItemClick(sender As Object, e As RadMenuEventArgs)
          //here goes you custom logic
       End Sub

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. Fabio Cirillo
    Fabio Cirillo avatar
    180 posts
    Member since:
    Jan 2010

    Posted 30 Jan 2013 Link to this post

    Ok,
    but if i write this code:
    OnItemClick="RadMenu1_ItemClick"
    the code behind start but i use this code:
    OnClientItemClicking="MenuOpenWindow"

    for call the radwindow. If use the code OnItemClick, dont function the code OnClientItemClicking.
    OnClientItemClicking call thid function:
    function MenuOpenWindow(sender, eventArgs) {
        if (eventArgs.get_item().get_text() == "Nuova immagine") {
            $find("<%= RadWindowLoadprofile.ClientID %>").show();
            eventArgs.set_cancel(true);
        }
        if (eventArgs.get_item().get_text() == "Visualizza immagine") {
            $find("<%= RadWindowAnteprimaProfile.ClientID %>").show();
            eventArgs.set_cancel(true);
        }
        if (eventArgs.get_item().get_text() == "Elimina immagine") {
            eventArgs.set_cancel(true);
        }
        if (eventArgs.get_item().get_text() == "Nuovo sfondo") {
            $find("<%= RadWindowLoadcard.ClientID %>").show();
            eventArgs.set_cancel(true);
        }
        if (eventArgs.get_item().get_text() == "Visualizza sfondo") {
            $find("<%= RadWindowAnteprimaCard.ClientID %>").show();
            eventArgs.set_cancel(true);
        }
        if (eventArgs.get_item().get_text() == "Elimina sfondo") {
            eventArgs.set_cancel(true);
        }
        if (eventArgs.get_item().get_text() == "I miei preferiti") {
            eventArgs.set_cancel(true);
        }
        if (eventArgs.get_item().get_text() == "Invita un amico") {
            $find("<%= RadWindowinvito.ClientID %>").show();
            eventArgs.set_cancel(true);                          
        }
        if (eventArgs.get_item().get_text() == "Modifica password") {
            $find("<%= RadWindowChangepwd.ClientID %>").show();
            eventArgs.set_cancel(true);
        }
        if (eventArgs.get_item().get_text() == "Elimina account") {
            $find("<%= RadWindowProfiledelete.ClientID %>").show();
            eventArgs.set_cancel(true);
        }
    }
    i need open radwindow or call webmethod from radmenu so or call this from javascript or call this from code behind, but the item of the radmenu should not remain selected after the click
  10. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 01 Feb 2013 Link to this post

    Hello,

    I would like to clarify that using following expression (eventArgs.set_cancel(true);) in your OnClientClicking client-side event handler will prevent firing the ItemClick server-side event as well. Therefore your custom code that sets the Selected property of the clicked item to false is not executed.
    I would recommend opening  the desired RadWindow control from your code behind and more specifically from your ItemClick server-side event handler.
    Here you could find more information about opening RadWindow control from server-side.
    I also would like to demonstrates that approach with an example in the code snippet below:
    //markup code
    <telerik:RadMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick">
        <Items>
            <telerik:RadMenuItem Text="Item 1"></telerik:RadMenuItem>
            <telerik:RadMenuItem Text="Item 2"></telerik:RadMenuItem>
            <telerik:RadMenuItem Text="Item 3"></telerik:RadMenuItem>
            <telerik:RadMenuItem Text="Item 4"></telerik:RadMenuItem>
            <telerik:RadMenuItem Text="Item 5"></telerik:RadMenuItem>
        </Items>
    </telerik:RadMenu>
    <telerik:RadWindow ID="RadWindow1" runat="server"></telerik:RadWindow>
    //code behind
    Protected Sub RadMenu1_ItemClick(sender As Object, e As RadMenuEventArgs)
           If e.Item.Text = "Item 2" Then
               Dim script As String = "function f(){$find(""" + RadWindow1.ClientID + """).show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"
               ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "key", script, True)
               e.Item.Selected = False
           End If

    You could use that approach for all your window controls and set the Selected property of the clicked menu item to false.

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017