Question

I have a problem with a data collection wizard.

My wizard has a number of client side validators, (regex, required field etc.) and they all work fine.

I have just added a CustomValidator to one of the controls, that is calling some server side code. (unfortunaltely it does have to be server side).

My problem is that this code seems to be called after the wizard has moved on to the next step (or is in the process of moving).

Thus, the fact that it returns false for the validation is of little use to me...

I am adding the Validator dynamically as part of my InitControl method as follows:

mustUploadAnImageValidator = new CustomValidator();
mustUploadAnImageValidator.ControlToValidate = radioButtonList.ID;
mustUploadAnImageValidator.ValidationGroup = "wizardGroup";
mustUploadAnImageValidator.ErrorMessage = "You must select a valid gallery image to use";
mustUploadAnImageValidator.Display = ValidatorDisplay.Static;
mustUploadAnImageValidator.ServerValidate += 
    new ServerValidateEventHandler(mustUploadAnImageValidator_ServerValidate);
mustUploadAnImageValidator.CssClass = "galleryValidationMessageTop";

This works for all other validators, but I can't figure out why the wizard is moving on before my server validation returns.

I've added a javaScript pop-up, called from the server side method, which basically says "I'm not valid" & this appears just after the screen moves on.

Any suggestions gratefully recieved.

Was it helpful?

Solution

I have managed to sort this out.

I have added an event handler for the NextButtonClick & PreviousButtonClick that simply calls the page validation again.

protected virtual void DataCollectionWizard_PreviousButtonClick(object sender, WizardNavigationEventArgs e)
    {
        //manually validate the page, as the automatic validation seems to ignore CustomValidators
        Page.Validate("wizardGroup");

        if (!Page.IsValid)
        {
            e.Cancel = true;
        }
    }

My server side validator is now being called twice, once by the original wizard code, which is then ignored, and a 2nd time by this method, which then stops the wizard moving on to the next step....

It's not the best fix in the world, but at least it's working! I'll update this post if I ever figure out what is actually going on.

OTHER TIPS

Make sure you're adding the control on every postback, in the Init event.

Edit

You also have to manually wire up the client side validation for custom validators.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top