I have created an event receiver on the "Task" list.

If the "Due Date" is null then the user should be redirected to the custom error page.

Custom error page resides in the SharePoint mapped folder under "Layouts" directory.

The event receiver code is as follows:

public override void ItemAdding(SPItemEventProperties properties)
        if (properties.AfterProperties["Due Date"] == null)
            properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
            properties.RedirectUrl = "_layouts/CustomErrorPage/DueDateErrorPage.aspx";
    catch (Exception ex)


The custom error page which is of type "Application Page" having name. "DueDateErrorPage.aspx". The mark up is:

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">


<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
 ERROR : You cannot create the task without due date

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
 Custom Error Page

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
 Custom Error Page

Though in IIS, under the _layouts direcory the page is available I am getting this output.

How should I tackle this error? Please help.

  • 1
    You probably want this in ItemUpdating; ItemAdding happens before any metadata gets entered (and you may just want to use a required field).
    – lgaud
    Jul 30 '13 at 13:14
  • 1
    This seems like an awful lot of work, with all the attendant maintenance and upgrade implications that every custom code effort entails, just to make the Due Date column a required field. Can't you just make this a required field in the normal way, or is there some more complex logic involved that you are not showing us? Jul 30 '13 at 17:19
  • No sir, that's not the matter. I am beginner in SharePoint so just as practice point of view of doing this... @DerekGusoff
    – users1100
    Jul 31 '13 at 3:40
  • Ahh, that makes sense now. I'm glad to see you've found a solution. Jul 31 '13 at 13:23

I did the same in my application but it dint work with adding an application page for error message. Then I tried adding a HTML page with error message and it worked fine.

Create a HTML page with the required error message and put it into the mapped folder, as you did for the Application page and do as follow

properties.RedirectUrl = "/_layouts/CustomErrorPage/Your HTML page.htm"

Put the following in the HTML page (not mandatory to follow the below, you can edit it as your wish)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<body style="background-color=#F0F8FF">
<div style="font-family:Verdana;font-size:smaller;color=Red;font-weight=bold">
    You cannot create the task without due date

  • Thanks for the reply.. The way you suggested is correct as well as I found the solution also..
    – users1100
    Jul 31 '13 at 3:48

Start the redirectUrl with a "/" like:

properties.RedirectUrl = "/_layouts/CustomErrorPage/DueDateErrorPage.aspx";
  • Sir, I made the changes as per your suggestion but getting the error "404 file not found".. @Robert Lindgren
    – users1100
    Jul 30 '13 at 13:08
  • I checked the IIS directory also after deploying and there file exists..
    – users1100
    Jul 30 '13 at 13:11
  • What is the full url you get back? You might need to add the root web url Jul 30 '13 at 13:37

First of all I first checked the url in web browser that is:


It was opening the page that means the page is available but there is something missing in the url only.

So by using the SPUrlUtility class I was able to redirect the page.

The changes I needed to made was:

properties.RedirectUrl = SPUrlUtility.CombineUrl(properties.WebUrl,"/_layouts/CustomErrorPage/DueDateErrorPage.aspx");

It's working perfectly..

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.