views:

99

answers:

2

In ASP.NET... Is there a way I can use validators just to show a warning (Ok / Cancel) msg box?

if the user chooses OK.. it should proceed submitting the page.

I know a javascript function could do the job. But there are many controls like that for me to check..

Just thought of checking whether validators will be of any help, before proceeding with Javascript.

Thanks

A: 

It can be done with alert (ok button) and confirm (ok, cancel) JavaScript functions. You don't need to use asp.net validators.

<asp:Button onClientClick="return confirm('Are you sure to proceed?');" />

Edit: if you need just to show validation warning to user you may enable / disable asp.net validators from JavaScript according to user's choice.

sashaeve
+3  A: 

You can define an arbitrary JavaScript function with the CustomValidator.ClientValidationFunction property.

<asp:CustomValidator ... ClientValidationFunction="AwesomeValidator"/>

And:

function AwesomeValidator(source, e)
{
    var x;

    if (valueIsBad(e.Value))
        x = confirm('Are you sure?');
    // do something with x...
}

More at MSDN.

Quick Joe Smith
+1 for naming the function AwesomeValidator.
Jason Berkan