Show custom error message instead of Web part access denied – SharePoint 2010

Many times while using “ListViewWebPart” you get the following error if the user does not have access to the list/library
Error Web Part Error: Access denied. You do not have permission to perform this action or access this resource”
clip_image00f2
Though the error is kind of explanatory but is not very user friendly. I have getting demands from lot of customers to replace this error with a custom error message. Let us see how we can achieve this using Jquery
1. Download latest version of Jquery
2. Edit Page where you have added you ListViewWebPart and add a “Content Editor Web part” at the end of the page. Make the web part hidden
3. Add the following JavaScript to the “Content Editor Web Part”

<script type="text/javascript" src="/Shared%20Document/jquery.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
$('div[errorwebpart="1"]').text('The content of this section is restricted to authorized users only.');
$('div[errorwebpart="1"]').addClass("ms-vb2");
}
);
</script>

Note: the path for the Jquery should be your path for the Jquery file

Once done you will be able to see the custom message instead of generic Sharepoint message

clip_image00v4

Related Post

1 thought on “Show custom error message instead of Web part access denied – SharePoint 2010”

Leave a Reply

Your email address will not be published. Required fields are marked *