How to cancel Finish button click in wizard control?

B

Bogdan

I have FinishDestinationPageUrl and OnFinishButtonClick set in a wizard.
I'd like to prevent the wizard to navigate to the url when finish button is
clicked while the page is invalid (i.e. one of the validators fails).

In the OnFinishButtonClick event handler I set the event args Cancel
property to true if the page is not valid. Unfortunately this does not seem
to stop the wizard from navigating to OnFinishButtonClick.

Can someone please give me some ideas on how to workaround this?

Thanks,
Bogdan
 
S

Scott M.

How about simply disabling the finish button until you are sure that the
data is valid?
 
B

Bogdan

Scott,

Thanks for the reply.

I need to perform a rather complex validation on the server side using a
custom validator. I don't think that disabling the finish button will work
in this case. Unless I'm missing something obvious...

I'm still puzzled by the behaviour of the Finish button. I could easily
cancel moving to the next page using the same technique.

Thanks,
Bogdan
 
S

Scott M.

You should be able to use the enable/disable feature of the button based on
the results of your custom validator. It's really very simple, in your
"valid" section of your custom validator code, set the enabled property of
the button to true and set it to false in the "invalid" section of the
validator's code.
 
B

Bogdan

Scott,

Thanks again for the reply.

I'm not sure if I described the problem clearly enough or I'm not quite
clear what you are suggesting. So please bear with me...

This is what I have:
Last step of my wizard control contains a field that needs to be
server-validated. That step is the only step that shows Finish button (it
is a finish step).
I have to have the Finish button enabled because this is the only way I
could submit the page, trigger validation, and navigate to another page on
success. But what I'd like to do is to 'come back' to the same step (in
other words: cancel or do not proceed) if server-validation fails (i.e. the
field in questions is invalid). I can't figure out how to do that. Once
the Finish button is pressed, there seem to be no way to prevent the
framework from navigating to the FinishDestinationPageUrl. The valid status
of the page and cancelling the event is ignored which I find inconsistent
with events generated by the Next button.

I think that programmatically clearing or setting (depending on validation
state) of the destination url will work but I wonder if there is a way of
avoid the hack.

Thanks again,
Bogdan
 
S

Scott M.

It's not a hack and here's the simplest way to do it:

Set the visible property of the Finish button to False.
Create a new button on that last page of the wizard and give it text of
"Validate Input".
Create a label on the final wizard step page called lblStatus.
Move this new button so that it is exactly over the Finish button.
In the click event handler of the new button, do your validation.
If the validation succeeds, make the visible property of the new button
false and make the visble property of the Finish button true.
If the validation fails populate lblStatus with a message indicating what
was wrong with the input and to try again.

-Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top