I have tried setting it in the code and also in the markup but when the Next Button is clicked, the page is validated, I want to prevnt this from happening and control when validation should occur and when not. Any suggestions or code samples would be appreciated
views:
1961answers:
1The easiest way to do this would be to remove all validator controls from the WizardStep
in which validation is to be skipped.
However, if you need advanced functionality, you will need to set the CausesValidation
property of the Next/Previous buttons in your StepNavigationTemplate
manually. The ASP.NET Wizard control does not expose properties that let you access the controls in the NavigationTemplates directly, nor does it expose any properties to access the NavigationTemplate. So, we need to rely on the FindControl
method to do all the searching.
A handy piece of information that I found while researching this problem was that at runtime the StepNavigationTemplate
is of an internal ASP.NET type called StepNavigationTemplateContainer
and has an ID "StepNavigationTemplateContainerID". This enabled me to locate the StepNavigationTemplate
and therefore, the Next Button.
Code follows:
protected void Wizard1_ActiveStepChanged(object sender, EventArgs e)
{
int step = Wizard1.ActiveStepIndex;
// Disable validation for Step 2. (index is zero-based)
if (step == 1)
{
ToggleValidation(false);
}
else // Enable validation for subsequent steps.
{
ToggleValidation(true);
}
}
private void ToggleValidation(bool flag)
{
WebControl stepNavTemplate = this.Wizard1.FindControl("StepNavigationTemplateContainerID") as WebControl;
if (stepNavTemplate != null)
{
Button b = stepNavTemplate.FindControl("StepNextButton") as Button;
if (b != null)
{
b.CausesValidation = flag;
}
}
}