I like to custom edit the permission of users after creating or editing an item.
- Using workflow for that was not accepted by client because sometime workflow is late to start.
- I found a Javascript approach of:
function PreSaveItem(){...}
But this not what I am looking for due to security, and I still dont think you can change permission of user in javascript (I hope not).
I just want to edit NewForm.aspx and add C# code that will be executed immediately before or just after item is added/edited.
Thanks
Best Answer
You will have to wait until the item has been created, and then
BreakRoleInheritance()
on it.However, be aware that you will have some problems, if a user adds the item and then immediately tries to open the "DispForm.aspx". This is because the event receiver works on a parallel thread and, if the
BreakRoleInheritance
is performed at that moment, the user may not have read access to the item. Hence, the "Access denied" error may appear.EDIT: When you want to deploy your event handler, you typically create a feature that can be activated/deactivated at the web scope. You then catch the "feature activated" and call a function like this:
The feature can be defined as:
EDIT2: if you really have to do it in the
newform.aspx
, you have to add some control that is rendered in the page. Inside that control, you set an 'OnSaveHandler"Then, implement your own save function: