Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
I am having trouble with custom validator client side validation. Please help..

I would like to have a Progress bar for synchronous custom validator call. This works but I need progress bar. Is it possible?

I tried a asynchronous web service call -submit button gooes to the next step before the validator returns-Using Icallbackeventhandler..

Thanking you,

smp
Posted

What you want to do is possible, but I'm not sure using a ASP.NET custom validator is the easiest way to go. If this custom validation is only on one or two pages, I'd just do the validation manually using a callback and some JQuery code.

Add a click event handler to your submit button (and any other button that should cause validation) that looks something like this:
$('.buttonsThatCauseValidation').live("click", function(event) {
    if (event.button != 2) { // Proceed if this is not a right-click
        // Display your progress bar/spinner/modal UI here.
        // Example using the JQuery BlockUI plugin: $.blockUI({ message: '<h1>Please wait while we begin processing your form.</h1>', css: { padding: '10px' } });
        <Insert CallbackReference Here>;
        return false; // Return false here to prevent the button from actually doing the postback or submitting the form.
    }
    return true;  // Return true here to allow the default action to occur.
});


Then in your client-side callback handler you check your validation result and either show an error message or proceed with the postback/submit operation.
function GetValidationCallbackResult(result) {
    // Hide your progress bar/spinner/modal UI here.
    // Example using the JQuery BlockUI plugin: $.unblockUI();
    if(result == "true") {
        <Insert PostbackReference Here>;
    }
    else {
        // Display the appropriate error message.
    }
}


Since you need callback and postback references, this code should be added using Page.ClientScript.RegisterClientScriptBlock().
 
Share this answer
 
v2
Hi Kythen ,
Thank you for your response.
When I used Icallbackeventhandler,submit button goes to the next step before the validator returns.

Synchronous JavaScript call using Scriptable XML Webservice (S-AJAX)[^]

I have used this method to make a synchronous call. But I wanted a progressbar with this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900