Show a custom message when e.Cancel() for Global Event handlers

Simple [A] asked on November 20, 2019 21:01

Hello friends,

I'm trying to set a custom message when doing a e.Cancel() on the following event: BizFormItemEvents.Insert.Before += insert_Before; before submitting the form.

However, I found out that, it is not possible. I even tried to throw a new exception directly with a custom message and it keeps showing the same error message. Also reviewed this article without luck: https://bitwizards.com/thought-leadership/blog/2014/september-2014/cancelling-out-of-a-global-event-handler-in-kentic

I'm using Kentico 12.0.41 MVC.

Any hint is always welcome

Thanks in advance

Recent Answers


Peter Mogilnitski answered on November 20, 2019 23:07 (last edited on November 20, 2019 23:08)

There are a couple approaches discussed in this tread. (Scroll down there another answer except the accepted one)

0 votesVote for this answer Mark as a Correct answer

Michal Samuhel answered on November 21, 2019 09:46

Thinking about this, in thread Peter linked, Lukas mentions custom form control which would work on administration backend, but on MVC application it will not work. I guess we need a bit more context in here. Simple [A] , you are mentioning that you are using MVC. Are you trying to use handler in MVC app? If it is in CMS what Peter posted is perfectly valid, but in MVC app, why not use controller action to validate data and cancel event.

1 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on November 21, 2019 13:52

I'm not really sure there is a way to pass a message from the event handler to the UI.

As long as you're using MVC you can always implement you custom form, or, at least, wrap Kentico one with your control and implement any check you need before saving data.

0 votesVote for this answer Mark as a Correct answer

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