【问题标题】:C# code behind Required validation必需验证背后的 C# 代码
【发布时间】:2011-03-14 07:39:50
【问题描述】:

我正在为多行文本框的必填字段验证器编写 C# 代码。

我在运行时遇到问题:

当我不会在 文本框

  1. 第一次点击提交(按钮)会显示错误消息

  2. 第二次点击提交将不会验证文本框并提交表单。

当我输入任何内容时,同样的两个问题 文本框内的文本。

总的来说它没有验证......

请帮助我了解以下代码中可能存在的错误。

    txtReport = new InputFormTextBox();
    txtReport.TextMode = TextBoxMode.MultiLine;
    txtReport.RichText = true;
    txtReport.RichTextMode = SPRichTextMode.Compatible;
    txtReport.Rows = 5;
    txtReport.Width = new Unit(200);
    txtReport.ID = "txtReport";
    txtReport.Text.Trim();
    this.Controls.Add(txtReport);


    reqVal = new RequiredFieldValidator();
    reqVal.ID = "reqVal";
    reqVal.ControlToValidate = txtReport.ID;

    reqVal.SetFocusOnError = true;
    reqVal.ErrorMessage = "*Comments field is mandatory";
    reqVal.Enabled = true;
    this.Controls.Add(reqVal);

提前致谢

【问题讨论】:

  • 您是否将.CausesValidation 属性设置为true
  • @KMan 我在按钮属性 button.CausesValidation = true;

标签: c# validation requiredfieldvalidator


【解决方案1】:

听起来您在第一次提交后没有重新添加验证器,导致第二次提交无法验证。但是从您发布的片段中很难分辨(在什么事件/方法中调用它?)。

【讨论】:

  • 在按钮事件中它被称为“button.CausesValidation=true;”
猜你喜欢
  • 2015-02-24
  • 2015-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-12
  • 1970-01-01
  • 2015-12-27
相关资源
最近更新 更多