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

Context Menu ItemClick serverSideEvent

8 Answers 190 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Chris O
Top achievements
Rank 1
Chris O asked on 29 May 2008, 07:51 PM
if i have a list of elements that display the menu when selected.  When a menu item is selected on the client it fires the server event  OnItemClick="ContextMenuSelected" 

html

<a ondblclick="showMenu(event)">102.</a>

protected

void ContextMenuSelected(object sender, RadMenuEventArgs e)

{

Telerik.Web.UI.

RadMenuItem ItemClicked = e.Item;
System.Diagnostics.Debug.WriteLine("Server event raised -- you clicked: " + ItemClicked.Text);
}

How can I tell which page element the item was selected from.  i want to know that it was 102. that the menu was called from

Thanks,
Chris

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 30 May 2008, 07:40 AM
Hello Chris Olsen,

RadMenu does not provide built-in support for that. However you can store the ID, or value of the clicked element in some hidden field and access it on the server side. Here is a quick example:

<input type="hidden" id="currentElement" />
<a ondblclick="showMenu(this, event)">102</a>

<script type="text/javascript">

function showMenu(element, e)
{
    var currentElement = $get("<%= currentElement.ClientID %>");
    currentElement.value = element.innerHTML;

    //Show the context menu here
}
</script>

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chris O
Top achievements
Rank 1
answered on 30 May 2008, 12:21 PM
Thanks, 

This did work with a modification.  I was unable to use
currentElement.value = element.innerHTML;
instead I had to use

currentElement.value = element.srcElement.childNodes[0].nodeValue;

Thanks for the idea.
Chris
0
John Fetherolf
Top achievements
Rank 1
answered on 11 Sep 2008, 01:53 PM
Just got around to needing RadContextMenu today and had to read through 11 pages of posts to find this answer :(

Anyway the ultimate question is:  If you allow a collection of targets (controls) on the server side, why on earth would the server event not need to know what the target control that caused the event was?  Is this going to be passed to the server in a future version of the controls?  This seems kind of silly to me that you can't determine the actual target of the context menu from the server-side events.

Kevin
0
Chad
Top achievements
Rank 1
answered on 19 Sep 2008, 06:48 PM
So is there no way to access the item that triggered the event without using javascript?

I'm trying to implement the context menu into a RadScheduler that is being used in MOSS as a webpart. I can get the menu to open but I can't tell it to show different options depending on the item the context menu was activated from.

If it's an appointment, show something.
If its a timeslot, show something different.
If it's neither, do nothing at all.

An example menu item would be "Change Color Red"... when clicked it would get the ID of the appointment and update that appointment's color field value on the MOSS list that the scheduler is tied to.

Server side access is a no go? =(
I hate javascript...
0
Marcel
Top achievements
Rank 1
answered on 25 Mar 2010, 11:24 AM
Storing the ID into a hidden field and posting it back to the server is an extremely disappointing answer, I must say. If RadContextMenu has a Targets collection and an OnItemClick server event, I at least expect to be able to access the target whose context menu was clicked.

Will this be fixed in a future release?
0
Veselin Vasilev
Telerik team
answered on 30 Mar 2010, 12:52 PM
Hello Marcel,

We will consider implementing a property in the event arguments which will contain the ID of the html element that was clicked.

All the best,
Veskoni
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.
0
Mark
Top achievements
Rank 1
answered on 10 Feb 2011, 12:33 PM
Did this get resolved?

I also have an issue.  I have a org chart that i have as a seperate project.

Im using

protected void SetContext()
{
    //    // Add file view context menu  
    int i = 0;
    while (i < Org1.ChartItems.Count)
    {
        ContextMenuControlTarget target = new ContextMenuControlTarget();
        string tg = Org1.ChartItems[i].ItemId.ToString();
        target.ControlID = "I" + tg;       
        radContextMenuOrgObject.Targets.Add(target);
        i++;
    }
}

to add the radcontextmenu on each control (they are divs).

However when i try to find out what targetitem called the contextmenu, it returns "undefined".

Am I doing something wrong?

<script type="text/javascript">
    function onClicking(sender, eventArgs) 
    {
        var item = eventArgs.get_item();
        var navigateUrl = item.get_navigateUrl();
        var targetitem = eventArgs.get_targetElement().value;
        alert(targetitem);
  
  /*      if (navigateUrl && navigateUrl != "#") 
        {
            var proceed = confirm("Navigate to " + navigateUrl + " ?");
            if (!proceed) {
                eventArgs.set_cancel(true);
            }
            else {
                eventArgs.set_cancel(false);
            }
        }*/
    }
</script>
0
Yana
Telerik team
answered on 15 Feb 2011, 02:00 PM
Hello Mark,

Could you please open a support ticket and send us a runnable page demonstrating the issue? Thanks

Kind regards,
Yana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Menu
Asked by
Chris O
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Chris O
Top achievements
Rank 1
John Fetherolf
Top achievements
Rank 1
Chad
Top achievements
Rank 1
Marcel
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Mark
Top achievements
Rank 1
Yana
Telerik team
Share this question
or