Asked by:
ItemUpdating Cancel ErrorMessage not shown on Standard SharePoint Error Page

Question
-
I have created an ItemUpdating event handler on a document library, the event is cancelled in certain scenarios by executing the following code in the event handler
properties.Cancel =
true;
properties.Status =
SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage =
"ADV number entered is not unique. Please try again";
The standard Sharepoint error message is shown but the error message set above is not displayed.
Can somebody help?
- Edited by ParamLondon Friday, August 13, 2010 9:39 AM title was spelt wrong
Tuesday, August 10, 2010 9:41 PM
All replies
-
First set the error message, then status and after that cancel.
properties.ErrorMessage = errorMessage; properties.Status = SPEventReceiverStatus.CancelWithError; properties.Cancel = true;
---
Rajesh | My Blog
MCTS - WSS AD, WSS Config, MOSS Config.Wednesday, August 11, 2010 1:12 AM -
I have tried the above suggestion and it still does not work.
I also made sure custom errors was turned on in the web.config to ensure the standard error page was shown, as below:
<customErrors mode="On" defaultRedirect="/_layouts/error.aspx" /> (Is the error page the right one?)
Here is my code as below:
public override void ItemUpdating(SPItemEventProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPWeb web;
DisableEventFiring();
int outValue;
try
{
int nextNumber = GetNextNumber(properties);
using (
web =
new SPSite(properties.SiteId).OpenWeb(
properties.RelativeWebUrl))
{
string documentNumberTypeColumn =
web.Lists[properties.ListId].Fields[
_documentNumberTypeColumnName].InternalName;
object documentNumberTypeValue =
properties.AfterProperties[documentNumberTypeColumn];
if (documentNumberTypeValue == null || documentNumberTypeValue.ToString() == string.Empty)
{
//perform logic - omitted here
}
else
{
properties.ErrorMessage = "Document number type has not been entered. Please try again";
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;
}
}
}
catch (Exception e)
{
PortalLog.LogString("Error occurred in ItemUpdating- " + e.Message +
"Stack Trace is " + e.StackTrace);
}
finally
{
EnableEventFiring();
}
});
}
Any ideas why this still doesn't work?
Wednesday, August 11, 2010 10:43 AM -
Hi ParamLondon,
I agree with Rajesh. You can also find sample code in MSDN: http://msdn.microsoft.com/en-us/library/ff713708%28office.12%29.aspx
So I think you should check the deployment steps of event handler. Did you restart IIS after you install your DLL into GAC?
Here is a completed example about creating custom event handler:
http://koenvosters.wordpress.com/2009/07/31/howto-create-an-event-handler-for-sharepointmoss-2007/
He also recommended the “SharePoint Inspector” to confirm whether the event handler is deployed correctly.
You can download it from: http://spi.codeplex.com/
Thursday, August 12, 2010 2:43 AM -
The event handler has been deployed in the standard way, i.e. using SharePoint solutions. And I always restart IIS and recycle the Windows Services Timer service after a deployment
I can debug the event handler when logged in on the server and running VS 2008, and have checked through Solution Management in SharePoint Central Admin, and the solution looks to be deployed correctly. I am sure that the event handler is deployed correctly.
Any other ideas on why the error message is not transferred to the standard SP error page would be appreciated.
Thursday, August 12, 2010 8:38 AM -
Did u get any solution? I am facing same issue.Thursday, September 2, 2010 12:16 PM
-
Hi all,
Please use Event Explorer http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?List=91f6455c%2D4448%2D4303%2D8a38%2Db1722e1522d1&ID=1589 of U2U they have documentation also.Open your site then your list and check if your event is registered correctly.Else register it using this too.
One more thing you have to do is Attach your code in visual studio and check if any exception blocking the error message
Destin- Proposed as answer by Aneesh_Argent Wednesday, September 8, 2010 12:22 PM
Thursday, September 2, 2010 12:26 PM -
Also make sure you call the base.ItemUpdating(properties); in the first line of the ItemUpdating method. For example:
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
// only perform if we have an Email column
if (properties.AfterProperties["Email"] != null)
{
// test to see if the email is valid
if (!IsValidEmailAddress(properties.AfterProperties["Email"].ToString()))
{
// email validation failed, so display an error
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;
properties.ErrorMessage = "Please enter a valid email address";
}
}
My SharePoint Blog - http://www.davehunter.co.uk/blog- Proposed as answer by ChrisL1945 Monday, March 11, 2013 6:54 AM
Monday, September 6, 2010 9:04 AM -
Even after using this, exception was shown on yellow screen or custom error page, if it is defined. I have created one error page and redirected user to that page.
HttpContext current;
public CalendarValidationEventHandler()
{
current = HttpContext.Current;
}public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
DisableEventFiring();if (ExecuteQuery(list, query) > 0)
{
current.Application["myError"] = ConfigurationKeys.EventError;
properties.ErrorMessage = ConfigurationKeys.EventError;
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;EnableEventFiring();
current.Response.Redirect("/_layouts/XYZ/EventExists.htm");
}EnableEventFiring();
}Tuesday, September 7, 2010 8:23 AM -
The SharePoint behaviour is to show an error message on a SharePoint branded page or ASP.NET if you have custom errors turned off.
My SharePoint Blog - http://www.davehunter.co.uk/blogTuesday, September 7, 2010 9:20 AM -
That previous post isn't strictly true, you need to alter the SafeMode tag also to get the SharePoint error page to display. This worked for me:
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
and
<customErrors mode="On" />
- Proposed as answer by Koheiden Saturday, October 15, 2011 12:00 AM
Wednesday, October 12, 2011 1:30 PM -
Thank you MrPack... Great solution!Saturday, October 15, 2011 12:04 AM
-
MrPack
I am having problems getting the SharePoint error page to display from my event receiver. I have checked the web.config as you suggested in this post and it looks correct. Do you have any other advise?
Thanks,
Mike
MikeThursday, December 22, 2011 3:49 PM -
HI follow the link for creating custom error page in share point
http://aidangarnish.net/post/Setting-up-a-SharePoint-custom-error-page.aspx
- Edited by Mike Walsh FIN Friday, December 30, 2011 11:10 AM sig out
Friday, December 30, 2011 7:10 AM