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

I have read here: DotVVM JavaScript events | DotVVM Documentation about the postbackRejected client-side event.

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

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.

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

How to achieve this?

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.

1 Like

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.

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

image

1 Like