1

I am using an ItemAdded event handler for doing some validation. If my validation fail is it possible to redirect the user to another page. Ideally it would be good to show the page in a dialog box.

Sadly setting the status on on the SPItemEventProperties to SPEventReceiverStatus.CancelWithRedirectUrl and setting the RedirectUrl does not work.

This is happening on a Document library. This means I can't do the validation in the ItemAdding event as BeforeProperties, AfterProperties & properties.ListItem does not contain the information. (http://www.synergyonline.com/Blog/Lists/Posts/Post.aspx?ID=122)

Update When trying out @Andy code below I get the following:

System.Web.HttpException was unhandled by user code 
Cannot redirect after HTTP headers have been sent

3 Answers 3

2

This works, but only if the form is open in Dialog mode, for some reason.

//Constructor                                   
System.Web.HttpContext _context = null;
public MyEventHandler()
{
    _context = System.Web.HttpContext.Current;
}

public override void ItemAdded(SPItemEventProperties properties)
{
    SPList list = properties.List;
    if (!list.NavigateForFormsPages)
    {
        if (_context != null)
        {
            _context.Response.Redirect(webUrl + "/someurl", false);
        }
    }
}
1
  • Sadly getting a "System.Web.HttpException was unhandled by user code" "Cannot redirect after HTTP headers have been sent"
    – John
    Jul 16, 2012 at 10:56
0

from my understanding about event receivers is that you cannot edit the users current session as it is back end work.

perhaps a workflow with a workflow history could be used in your case.

if the validation fails you can log the desired redirection URL in the history they can follow it and rerun the workflow when they have made the validation changes

0

If you want to add validation and have the possibility of canceling the update and redirect the user, then you should implement the ItemAdding event receiver instead of the ItemAdded.

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.