I have got A custom action in Open Menu. But i must get ID of element. How could I get ID when I clicked three dots on C# code:

closed as unclear what you're asking by Dikesh Gandhi, Asad Refai, Mohamed El-Qassas MVP Jun 26 '17 at 0:17

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I've shown in another answer how you can locate elements (and their IDs) by using Chrome. Find it here. – moe Jun 22 '17 at 13:06
  • But I need a ID of clicked element. – Grzegorz Z Jun 22 '17 at 13:13
  • 1
    When a button/element/anything is clicked, its ID doesn't necessarily change. If it's designed like that, then it might change, but for what I've witnesses, in SharePoint's context clicked elements don't usually have a dynamically changing ID. – moe Jun 22 '17 at 13:16
  • Yes I know that, but how could I get in C# code. I must always use javascript ? or there is a method to get IDs. – Grzegorz Z Jun 22 '17 at 13:22
  • On the C# language. – Grzegorz Z Jun 22 '17 at 13:35

You can't do it using C#. You can use Javascript code to get the item ID of selected Item. check my sample code :

var ItemID;
var context = SP.ClientContext.get_current();
var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
var list = context.get_web().get_lists().getByTitle("List_title");
var item;
for (item in selectedItems)
    var mySelItem = list.getItemById(selectedItems[item].id);
if(selectedItems.length == '1')
  alert("Selected Items is is: "+ ItemID);
else{ alert("Please Select only one item"); }

OR some Reference : https://social.technet.microsoft.com/Forums/office/en-US/e34e59eb-dc77-47e5-8f42-5d27b6ae925b/sharepoint-2010-get-id-of-selected-list-item-using-c

  • Thanks, but how to fire the javascript ? – Grzegorz Z Jun 23 '17 at 9:32
  • There is a mistaqe, because it not showing me after loop for. – Grzegorz Z Jun 23 '17 at 11:18
  • 1
    using ClientScript.RegisterStartupScript(params).. you can call javascript code in your code behind file. MSDN ; msdn.microsoft.com/en-us/library/z9h4dk8y(v=vs.110).aspx – DvG Jun 23 '17 at 11:25
  • 1
    I have corrected my code – DvG Jun 23 '17 at 11:51
  • I don't cnow why, but when I set "SP.ListOperation.Selection.getSelectedItems(context);" the javascript don't show me. – Grzegorz Z Jun 29 '17 at 10:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.