Essentially the problem that this person seems to need to overcome is that he doesn't want the user to be able to continue to the next step when invalid data has been entered.
Including a Page.IsValid test on the button click does not stop the user from continuing. This is a problem I have encountered, and as yet am yet to resolve.
if the page.isvalid = false, the wizard will still navigate to the next step.
The wizard.ActiveStepChanged event fires no matter what.
I'm also at exactly the same point as this guy. The page is not valid, and I can get that information when the user clicks the next button, but for some reason I'm not able to prevent the wizard going on to the next step.
OK, so I've been hacking away at this problem all morning and have managed to put together a clunky, but eventually effective, workaround.
My testing assured me that my various validation controls were working correctly, i.e. the Page.IsValid property was always true or false respectively (I'm talking here only about server-side validation). I had an event handler assigned to the OnNextButtonClick
attribute which was getting called and could access the Page.IsValid property, but could not stop the wizard progressing to the next step. In the end, I created two handlers, for the NextButtonClick and ActiveStepChanged events and used some page-scope properties
to track stuff.
Here's the relevant bits of code:
public partial class SomePage : System.Web.UI.Page
{
int WizardFormStep;
bool IsWizardStepValid;
Just spent 4 hours on this before finding this post, thought I was going crazy! Can't stop that wizard from moving to the next step. Any other options or fixes on this?
I understand your frustration, this would appear to be a genuine flaw in the way these asp:Wizard's work. I've continued to use the fix I've demonstrated above in a major project using these wizards across about 20 pages and it's certainly proven to be stable
and effective. I've got a tiny, lingering doubt that I'm missing something obvious, however for now I'm sticking with I've got. Aside from this flaw, I've found the use of these wizards very effective. It removes a lot stuffing around switching views and messing
around with the viewstate.
I expect if you really wanted you could create your own wizard that inherits from the standard one and work the fixes in at that level, which would avoid having to carry this patch code around for every page that you want to have the wizard on.
Hi all, I have mucking around with this issue for too long as well. I notice that yes, validation is working but no the wizard will not stop going to the next step unless you add this code:
Protected Sub AddDriverWizard_NextButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
If Not Page.IsValid Then
e.Cancel = true
End If
Return
End Sub
Many thanks to nheaton for the simple and elegant solution, and to mattbug for translating it into VB for me... both are highly appreciated!
I finally got some time to get back to this issue today and plugged those few extra lines into my wizard pages. They seem to be working fine now. Server side validation once again blocks the wizard from advancing to the next page. I hope Microsoft fixes
this!
Also, thanks to Mick Byrne for his code contribution back in August. I didn't get a chance to try his solution, but many thanks anyway.
oblongmouth
Member
39 Points
8 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Aug 10, 2006 11:34 AM|LINK
Including a Page.IsValid test on the button click does not stop the user from continuing. This is a problem I have encountered, and as yet am yet to resolve.
if the page.isvalid = false, the wizard will still navigate to the next step.
The wizard.ActiveStepChanged event fires no matter what.
mikbyrne
Member
59 Points
13 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Aug 14, 2006 08:03 AM|LINK
Would appreciate some feedback or a workaround.
Web Projects Director
mikbyrne
Member
59 Points
13 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Aug 15, 2006 01:49 AM|LINK
My testing assured me that my various validation controls were working correctly, i.e. the Page.IsValid property was always true or false respectively (I'm talking here only about server-side validation). I had an event handler assigned to the OnNextButtonClick attribute which was getting called and could access the Page.IsValid property, but could not stop the wizard progressing to the next step. In the end, I created two handlers, for the NextButtonClick and ActiveStepChanged events and used some page-scope properties to track stuff.
Here's the relevant bits of code:
public partial class SomePage : System.Web.UI.Page
{
int WizardFormStep;
bool IsWizardStepValid;
protected void Page_Load(object sender, EventArgs e)
{
IsWizardStepValid = true;
WizardFormStep = uxDonateWizard.ActiveStepIndex;
// etc...
}
protected void ValidateNextButtonClick(object sender, EventArgs e)
{
IsWizardStepValid = Page.IsValid;
}
protected void ValidateStepChange(object sender, EventArgs e)
{
if (!IsWizardStepValid)
{
uxWizard.ActiveStepIndex = WizardFormStep;
}
}
}
So far, this seems to be working well. I've also added an attribute to my 'Previous' buttons to specify CausesValidation="false".
Hope this works for you Mr Spin.
Mick
Web Projects Director
aspdotnetnew...
Member
440 Points
91 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Oct 24, 2006 06:11 PM|LINK
Just spent 4 hours on this before finding this post, thought I was going crazy! Can't stop that wizard from moving to the next step. Any other options or fixes on this?
Thanks
mikbyrne
Member
59 Points
13 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Oct 24, 2006 10:34 PM|LINK
Hi there,
I understand your frustration, this would appear to be a genuine flaw in the way these asp:Wizard's work. I've continued to use the fix I've demonstrated above in a major project using these wizards across about 20 pages and it's certainly proven to be stable and effective. I've got a tiny, lingering doubt that I'm missing something obvious, however for now I'm sticking with I've got. Aside from this flaw, I've found the use of these wizards very effective. It removes a lot stuffing around switching views and messing around with the viewstate.
I expect if you really wanted you could create your own wizard that inherits from the standard one and work the fixes in at that level, which would avoid having to carry this patch code around for every page that you want to have the wizard on.
Good luck
Web Projects Director
aspdotnetnew...
Member
440 Points
91 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Oct 24, 2006 11:34 PM|LINK
This guy has a nice answer, http://forums.asp.net/thread/1385194.aspx
I used it, works great.
nheaton
Member
14 Points
2 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Dec 20, 2006 07:06 PM|LINK
Hi all, I have mucking around with this issue for too long as well. I notice that yes, validation is working but no the wizard will not stop going to the next step unless you add this code:
<
asp:Wizard OnNextButtonClick="AddDriverWizard_NextButtonClick" ID="AddVehicleWizard" runat="server"> protected void AddDriverWizard_NextButtonClick(object sender, WizardNavigationEventArgs e){
if (!Page.IsValid)
{
e.Cancel = true;
}
return;
}
mattbug
Member
535 Points
146 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Mar 16, 2007 02:19 PM|LINK
The post above should definitely be marked as the answer. Nice solution, nheaton!
..and for those more VB-oriented:
<asp:Wizard OnNextButtonClick="AddDriverWizard_NextButtonClick" ID="AddVehicleWizard" runat="server">
Protected Sub AddDriverWizard_NextButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
If Not Page.IsValid Then
e.Cancel = true
End If
Return
End Sub
SpinMap
Member
36 Points
10 Posts
Re: Adding Wizard StartNavigationTemplate breaks server validation
Mar 21, 2007 07:20 PM|LINK
Many thanks to nheaton for the simple and elegant solution, and to mattbug for translating it into VB for me... both are highly appreciated!
I finally got some time to get back to this issue today and plugged those few extra lines into my wizard pages. They seem to be working fine now. Server side validation once again blocks the wizard from advancing to the next page. I hope Microsoft fixes this!
Also, thanks to Mick Byrne for his code contribution back in August. I didn't get a chance to try his solution, but many thanks anyway.
-Christiaan
dustink
Member
2 Points
1 Post
Re: Adding Wizard StartNavigationTemplate breaks server validation
Nov 08, 2007 10:22 PM|LINK
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
if (!Page.IsValid)
{
e.Cancel = true;
return;
}
.
.
.
}