Custom Error message

arbab anis asked on July 20, 2017 06:57

Hi all, I am using a custom module to handle duplicate record creation in content tree, which is working fine but it shows Kentico Default Error Message i want my own custom Error message for this Particular Case. *Note:Usinge Kentico 10*

Correct Answer

Mike Wills answered on July 20, 2017 19:22

Hi Arbab,

I'm guessing that your module uses an Insert.Before event handler to make sure an added document is not a duplicate of an existing one. For example, you may want to allow only one document of a certain page type to be a child of another page type. If you are enforcing uniqueness in a global event handler like Insert.Before, the most you can do is cancel the event and throw an exception, like this:

e.Cancel();
throw new ApplicationException("There is already a, " + restrictedClassName + ", node under this page.");

However, this doesn't change the error message displayed to a user in the out-of-the-box form for new pages.

Here's a solution:

https://devnet.kentico.com/questions/user-friendly-error-message-from-global-event-handler

Summary: Change the generic error message that is provided to include a link to the Event Log, where the user could see the error. To do that, add a string with the key "General.ErrorDuringSave" as a new resource string in the Localization app. Give the string a new value with a like to the Event Log like this:

An error occurred. Please see <a href="../../../../CMSModules/EventLog/EventLog.aspx">event log</a> for more details.

Mike

2 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on July 20, 2017 14:19

can you provide some additional information or a screen shot?

is the error message just the red message bubble on the top of the custom user interface?

are you getting a server error page and that's what you want to customize?

If you properly catch your errors in a try catch you should be able to implement whatever error type thing you want, but you need to provide more context for us to be able to help

1 votesVote for this answer Mark as a Correct answer

Lukáš Gancarčík answered on July 21, 2017 10:23

Hi Arbab,

there is probably also another approach:

  • you can create your custom form control (https://docs.kentico.com/k10/custom-development/developing-form-controls)

  • there is a isValid() method which returns true if condition is met. Otherwise, it returns false and displays an error message, which you can customize based on your needs. You can find example here: https://docs.kentico.com/k10/custom-development/developing-form-controls/example-developing-custom-form-controls

  • for each of your page type you would need to chose your new custom form control as source for Page name (as you can see here: https://www.screencast.com/t/Tuul4uuLoi3D

Lukas

2 votesVote for this answer Mark as a Correct answer

arbab anis answered on July 26, 2017 08:25

Thanks Lukáš Gancarčík

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.