In SharePoint: SPUtility class contains two methods to achieve this.
Success Message:
SPUtility.TransferToSuccessPage: It is used to display a Success Message, and it has two overloads.
SPUtility.TransferToSuccessPage Method (String message)
Example:
SPUtility.TransferToSuccessPage("Welcome, You are in Success Page");
Figure (1) shows the output of this code. In this case the “Ok” button will redirect to the current SharePoint Site home page.
SPUtility.TransferToSuccessPage Method (String message, String nextUrl, String linkText, String linkUrl)
Example:
SPUtility.TransferToSuccessPage("Welcome, You are in Success Page", "/SitePages/Continue.aspx", "", "");In this case the “Ok” button will redirect to “"/SitePages/Continue.aspx” page.
Error Message:
The same is applied to SPUtility.TransferToErrorPage: it is used to display error message.
SPUtility.TransferToErrorPage(String message)Example:
SPUtility.TransferToErrorPage("Sorry it seems that you did a mistake. This is the error page");