views:

1961

answers:

1

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

+3  A: 

The 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;
    }
  }
}
Cerebrus
Wizard1_ActiveStepChanged event is not firing.any ideas?
chugh97
You'll have to wire it up, pal! Use the Visual Studio Property window's Event tab.
Cerebrus
I have wired it up , but the event is not firing. Do I have to increase the ActiveStepIndex in NextButtonClick eventhanlder for it to fire?
chugh97
No, if the event itself is not firing, you have not wired it up correctly. Try placing a breakpoint in the handler to verify that it is not firing.
Cerebrus