This is a migrated thread and some comments may be shown as answers.

Click on item child of the radmenu

8 Answers 385 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Fabio Cirillo
Top achievements
Rank 1
Fabio Cirillo asked on 25 Jan 2013, 10:33 AM
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

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Jan 2013, 11:42 AM
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.
0
Fabio Cirillo
Top achievements
Rank 1
answered on 25 Jan 2013, 03:31 PM
hi
its good thanks you
0
Fabio Cirillo
Top achievements
Rank 1
answered on 28 Jan 2013, 09:16 AM
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 
0
Shinu
Top achievements
Rank 2
answered on 28 Jan 2013, 10:40 AM
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.
0
Fabio Cirillo
Top achievements
Rank 1
answered on 28 Jan 2013, 12:01 PM
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

0
Boyan Dimitrov
Telerik team
answered on 29 Jan 2013, 04:42 PM
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.
0
Fabio Cirillo
Top achievements
Rank 1
answered on 30 Jan 2013, 09:08 AM
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
0
Boyan Dimitrov
Telerik team
answered on 01 Feb 2013, 04:33 PM
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.
Tags
Menu
Asked by
Fabio Cirillo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Fabio Cirillo
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or