# \[page lifecycle series\] postbackRejected handler not firing after server validation fails

**URL:** <https://forum.dotvvm.com/t/page-lifecycle-series-postbackrejected-handler-not-firing-after-server-validation-fails/165>\
**Category:** Discussion in English\
**Created:** [March 3, 2024, 11:26pm UTC](https://forum.dotvvm.com/t/page-lifecycle-series-postbackrejected-handler-not-firing-after-server-validation-fails/165 "2024-03-03T23:26:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [March 3, 2024, 11:26pm UTC](https://forum.dotvvm.com/t/page-lifecycle-series-postbackrejected-handler-not-firing-after-server-validation-fails/165/1 "2024-03-03T23:26:45Z")

</div>

I have read here: [DotVVM JavaScript events | DotVVM Documentation](https://www.dotvvm.com/docs/4.0/pages/concepts/client-side-development/dotvvm-javascript-events) about the postbackRejected client-side event.

 ![image](https://forum.dotvvm.com/uploads/default/original/1X/2217bf141b3db6da4e835f6168484e4981c1b76f.png)

My case is that a server validation fails and a model error is added and then request is interrupted.

 ![image](https://forum.dotvvm.com/uploads/default/original/1X/9134cb02d008f11a5c605198fde42ee50ec3b9ef.png)

I want to close a modalDialog after the validator is shown in the browser (it is shown, it works) but I need to identifiy the case of failed server validation as to close the modal only in this case.

 ![image](https://forum.dotvvm.com/uploads/default/original/1X/c2fbeaa816f2d22f563b5bcedeca7fe63a8cd32b.png)

This does nothing at all. The client-side breakpoint inside browser dev tools does not fire anywhere inside this handler.

How to achieve this?

---

<div class="post-metadata">

**Author:** ![exyi](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/exyi/32/9_2.png) [@exyi](https://forum.dotvvm.com/u/exyi)\
**Post date:** [March 4, 2024, 9:37am UTC](https://forum.dotvvm.com/t/page-lifecycle-series-postbackrejected-handler-not-firing-after-server-validation-fails/165/2 "2024-03-04T09:37:26Z")

</div>

`postbackRejected` only occurs if the postback is cancelled before contacting the server – it should be raised when client-side validation fails.

If server side validation fails, the postback proceeds normally, it will trigger the `afterPostback` event with `arg.error.reason.type == "validation"`. The validation errors are applied at that point, you can just read the `dotvvm.validation.errors`.

In case you’d want to see all validation failures, I’d just watch the `dotvvm.validation.events.validationErrorsChanged` event.

---

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [March 4, 2024, 11:48am UTC](https://forum.dotvvm.com/t/page-lifecycle-series-postbackrejected-handler-not-firing-after-server-validation-fails/165/3 "2024-03-04T11:48:34Z")

</div>

> [@exyi](#):
>
> the postback proceeds normally

Except that my confirm modal does not close when returning to client-side even though I close it in code-behind prior to calling `Context.FailOnInvalidModelState();` and I’m forced to deal with closing it by script code.

But if server validation succeeds, the modal is closed when returning to client-side.

---

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [March 4, 2024, 9:28pm UTC](https://forum.dotvvm.com/t/page-lifecycle-series-postbackrejected-handler-not-firing-after-server-validation-fails/165/4 "2024-03-04T21:28:08Z")

</div>

In cases where I need to discriminate client-side actions based on at most the validation target, this did the trick:

![image](https://forum.dotvvm.com/uploads/default/original/1X/1f2a9151f98ec2b85a2f56c8340c032e73a5e497.png)
