How to redirect to the SharePoint Success or Error Message page


In this article we will be seeing how to redirect to the SharePoint Success or Error message page.

In this article I will be creating a visual web part with two buttons - Success and Error button.

On click event of Success button, it will be redirected to the SharePoint Success page.

On click event of Error button, it will be redirected to the SharePoint Error page.

Steps Involved:

  • Open Visual Studio 2010.
  • Create a Visual Web part.
  • Add two buttons Success and Error.
  • Add the following Namespace.
     
    • using Microsoft.SharePoint.Utilities;

  • Replace the code for btnSuccess_Click event with the following

    SPUtility.TransferToSuccessPage("Operation Completed Successfully");
     
  • Replace the code for btnError_Click event with the following

    Exception ex = new Exception("Operation Failed");
    SPUtility.TransferToErrorPage(ex.Message);
     
  • Build and deploy the solution.
  • Add the web part in the SharePoint site.

    share1.gif
     
  • On click of Success button it will be redirected to the following page

    share2.gif
     
  • On click of Error button it will be redirected to the following page

    share3.gif