Some scenarios developers may want to restrict users from deleting webparts from a page, the scenarios varies.
SPWebPartManager has got a event named ‘OnWebPartDeleting’.The issue here is, the deletion of the webpart cannot be
avoided by setting the WebPartCancelEventArgs.Cancel = true; within the ‘OnWebPartDeleting’ event.
So the SPWebPartManager’s ‘OnWebPartDeleting’event is not going to help us in accomplishing our requirement, here I have a workaround, it may help you!
protected void On_WebPartDeleting(object sender, WebPartCancelEventArgs e)
Page.Response.Write("Sorry! This webpart cannot be deleted!<br>");
e.Cancel = true;
<WebPartPages:SPWebPartManager OnWebPartDeleting="On_WebPartDeleting" id="m" runat="Server"/>
As a workaround your can implement this, not sure you like this approach:)
Develop a custom HttpModule to trace the WebPart delete events, basically tracing the ‘__EVENTARGUMENT’ value.
See below the implementation.
This is a tricky workaround, however if you are looking for options to achieve this functionality then this would help.