I wanted to add following code to a Script Editor Web Part, but I am not sure which tags this code needs and if it will even work by adding it in a Script Editor:

SPList list = site.RootWeb.Lists["YourListName"];
SPField field = list.Fields["Name"];
field.CalloutMenu = false;
field.CalloutMenuAllowed = SPField.ListItemMenuState.Prohibited;
field.ListItemMenu = true;
field.ListItemMenuAllowed = SPField.ListItemMenuState.Required;

Thanks in advance.

  • You are mixing up Server Side and Client Side; this code is Server side code, which needs to execute on the server. WebPart contents are Client (Browser) side and only accept things the Browser can do (HTML, JavaScript) – Danny '365CSI' Engelman May 17 '16 at 10:37

Any C# code is need to compile first by the compiler, and as we all know the code kept in Script Editor WebPart is not compiled. The content kept in Script Editor WebPart is executed by browser hence we cannot use Script Editor WebPart for writing C# code as C# code cannot be executed by browser.

Let me know your thoughts.

  • Thank you very much. That answered my question. I've never worked with C#, I just found this code in order to customize the context menu of SharePoint. But then I have to look for any js (Script Editor) solution. – SteffPoint May 17 '16 at 10:39

Script Editor only supports JavaScript code, so you cannot user C# in there.

  • Thank you very much for answering my question. I have to look for a JavaScript solution then :) – SteffPoint May 17 '16 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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