chu*_*h97 1 asp.net controls wizard
我已尝试在代码中和标记中设置它,但是当单击下一个按钮时,页面已经过验证,我希望在验证发生时以及何时不发生时将其发生并控制.任何建议或代码样本将不胜感激
最简单的方法WizardStep是从要跳过验证的所有验证器控件中删除.
但是,如果您需要高级功能,则需要手动设置CausesValidation"下一个/上一个"按钮的属性StepNavigationTemplate.ASP.NET向导控件不公开允许您直接访问NavigationTemplates中的控件的属性,也不公开任何属性来访问NavigationTemplate.因此,我们需要依靠该FindControl方法来进行所有搜索.
我在研究这个问题时发现的一条便利信息是,在运行时,StepNavigationTemplate它是一个内部ASP.NET类型,名为StepNavigationTemplateContainer"StepNavigationTemplateContainerID".这使我能够找到StepNavigationTemplate下一个按钮.
代码如下:
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11645 次 |
| 最近记录: |