Client-Side Confirmation on ASPxButton with CausesValidation=true

If you use DevExpress and its ASPxButton, you can add client-side confirmation of a button press by setting the button’s ClientSideEvents.Click property to contain Javascript code like this:

MyButton.ClientSideEvents.Click =
  @"function(s,e) {
      e.processOnServer = confirm('execute this action?');
    }";

If the button’s CausesValidation property is set, however, this event handler will be called even if client-side validation raises validation errors. In this case, the confirmation dialog should not be displayed.

This can be solved by calling the ASPxClientEdit.ValidateGroup() client API before displaying the confirmation dialog:

MyButton.ClientSideEvents.Click =
  @"function(s,e) {
      e.processOnServer =
        ASPxClientEdit.ValidateGroup('" + MyButton.ValidationGroup + @"') 
        && confirm('execute this action?');
    }";
Advertisements

One Response to Client-Side Confirmation on ASPxButton with CausesValidation=true

  1. darin says:

    Thank you very much. I didnt know e.processOnServer. I tried to prevent server submission if validation fails. Thanks again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: