简体   繁体   中英

How do I disable my ASP.NET AJAX ConfirmButtonExtender when page validation fails?

I've got a submit button using Microsoft's ConfirmButton extender to ask "Are you sure?". However it fires regardless of whether or not the page passes client-side validation.

<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidatorTextBox1"
    runat="server"
    ControlToValidate="TextBox1"
    ErrorMessage="First name is required"
    Display="Dynamic" />
...
<asp:Button ID="Button1"
    runat="server"
    Text="Submit"
    CausesValidation="True" />
<ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtenderButton1"
    runat="server"
    TargetControlID="Button1"
    ConfirmText="Are you sure?" />
...
<asp:ValidationSummary id="ValidationSummary1"
    runat="server"
    ShowMessageBox="True" />

So, if a user leaves a required field blank and clicks the "Submit" button. She'll see two message boxes:

One for validation...

ValidationSummary ShowMessageBox http://img120.imageshack.us/img120/8305/validationzn6.gif

Then one for confirmation ...

ConfirmButtonExtender http://img228.imageshack.us/img228/678/confirmationam3.gif

(Note: OK and Cancel both just cancel.)

It doesn't make sense for the confirmation to show up if validation fails. It should be one or the other. How can I do this?


Update:

If I try to use ConfirmOnFormSubmit, then I get this warning:

Validation (ASP.Net): Attribute 'ConfirmOnFormSubmit' is not a valid attribute of element 'ConfirmButtonExtender'.

Validation (ASP.Net): Attribute 'ConfirmOnFormSubmit' is not a valid attribute of element 'ConfirmButtonExtender'. http://img382.imageshack.us/img382/1391/confirmonformsubmitow3.gif

Make sure the ConfirmOnFormSubmit is set to TRUE on the ConfirmButtonExtender.

From the example site :

ConfirmOnFormSubmit - True if the confirm dialog should wait until just before the form submits to display. This is useful when ASP.NET validators are in use and the confirm should be shown only after all validators pass.

EDIT: According to that website it is valid. Try updating to the latest version and or ignore the intellisense and just see what happens when you post it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM