在ASP.NET向导控制 - 如何设置Next按钮CausesValidation属性设置为false [英] Wizard Control in ASP.NET - How to set the NextButton Causesvalidation property to false

查看:352
本文介绍了在ASP.NET向导控制 - 如何设置Next按钮CausesValidation属性设置为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试在code和也,但点击下一步按钮时,页面验证标记设置它,我想prevnt这种情况的发生和何时进行验证控件,当不。任何建议或code样品将AP preciated

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

推荐答案

要做到这将是从的WizardStep 中验证删除所有验证程序控件的最简单方法被跳过。

The easiest way to do this would be to remove all validator controls from the WizardStep in which validation is to be skipped.

不过,如果你需要高级功能,您将需要设置一个/ previous按钮的的CausesValidation 属性在 StepNavigationTemplate 手动。 ASP.NET的向导控件不公开,使您可以直接访问NavigationTemplates控件的属性,也没有公开任何属性来访问NavigationTemplate。因此,我们需要依靠的FindControl 方法做所有的搜索。

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.

一个得心应手的资料片,我发现虽然研究这个问题是,在运行时, StepNavigationTemplate 是所谓的内部ASP.NET类型的 StepNavigationTemplateContainer 并有一个ID为StepNavigationTemplateContainerID。这使我能够找到 StepNavigationTemplate ,因此,下一步按钮。

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如下:


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;
    }
  }
}

这篇关于在ASP.NET向导控制 - 如何设置Next按钮CausesValidation属性设置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆