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

RadContextMenu for multiple controls, how to know which one call it

1 Answer 117 Views
Menu
This is a migrated thread and some comments may be shown as answers.
reguapo
Top achievements
Rank 1
reguapo asked on 11 Jul 2013, 02:42 PM
I have multiple RadListBox that basically are doing the same and has more likely the same behavior except maybe for the data, so I want to use the same RadContextMenu for all of them but on the OnItemClick(server side) I need to know which of those controls call it, How can I approach this?
Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Jul 2013, 06:34 AM
Hello Reguapo,

Try the following markup,JS and C# to achieve your scenario
aspx:
<telerik:RadListBox ID="RadListBox1" runat="server">
    <Items>
        <telerik:RadListBoxItem Text="001" />
        <telerik:RadListBoxItem Text="002" />
        <telerik:RadListBoxItem Text="003" />
        <telerik:RadListBoxItem Text="004" />
        <telerik:RadListBoxItem Text="005" />
    </Items>
</telerik:RadListBox>
<br />
<br />
<telerik:RadListBox ID="RadListBox2" runat="server">
    <Items>
        <telerik:RadListBoxItem Text="001" />
        <telerik:RadListBoxItem Text="002" />
        <telerik:RadListBoxItem Text="003" />
        <telerik:RadListBoxItem Text="004" />
        <telerik:RadListBoxItem Text="005" />
    </Items>
</telerik:RadListBox>
<telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnClientItemClicked="OnClientItemClicked"
    OnItemClick="RadContextMenu1_ItemClick">
    <Targets>
        <telerik:ContextMenuElementTarget ElementID="RadListBox1" />
        <telerik:ContextMenuElementTarget ElementID="RadListBox2" />
    </Targets>
    <Items>
        <telerik:RadMenuItem Text="1001" />
        <telerik:RadMenuItem Text="1002" />
        <telerik:RadMenuItem Text="1003" />
    </Items>
</telerik:RadContextMenu>
<asp:HiddenField ID="ListID" runat="server" />
JS:
<script type="text/javascript">
    function OnClientItemClicked(sender, args) {
 
        var ctrlID = document.getElementById("ListID");
        var listbox = args._targetElement.id;
        if (listbox.indexOf("RadListBox1") == 0) {
 
            ctrlID.value = "RadListBox1";
        }
        else if (listbox.indexOf("RadListBox2") == 0) {
 
            ctrlID.value = "RadListBox2";
        }
        else {
        }
    }
</script>
C#:
protected void RadContextMenu1_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
  {
      if (ListID.Value == "RadListBox1")
      {
 
      }
      else if (ListID.Value == "RadListBox2")
      {
 
      }
  }

Thanks
Shinu.
Tags
Menu
Asked by
reguapo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or