验证没有激发动态

时间:2014-07-23 15:47:16

标签: c# asp.net

从后面的usercontrol代码处理时,我的验证器没有触发。我的usercontrol包含以下内容:

<asp:TextBox ID="txtSource" cssClass="value"
    ValidationGroup="formbuilder" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RFV" runat="server"  
    ControlToValidate="txtSource" Enabled="true" ErrorMessage="*required"    
    ValidationGroup="formbuilder"></asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="REV" runat="server"
    ValidationGroup="formbuilder" ControlToValidate="txtSource" Enabled="false">
</asp:RegularExpressionValidator>

正如你所看到的,我必须输入errormessage并启用它才能触发它。我的用户控件代码如下。我正在设置两个必需的变量。

public bool EnabledRequiredField
{
    set { RFV.Enabled = value; }
}        

public bool EnabledRegularExpression
{
    set { REV.Enabled = value; }
}

private string _ErrorMsgForRequiredField;

public string ErrorMsgForRequiredField
{
    get { return _ErrorMsgForRequiredField; }
    set { RFV.ErrorMessage = value; }
}

但除非我硬编码Enabled =&#34; true&#34;和ErrorMessage =&#34; *必需&#34;,它不会触发。当我把它放在硬编码中时它确实如此。有任何想法吗?我通过以下方法加载控件。

 if (control.Required == "true")
 {
     textBoxControl.EnabledRequiredField = true;  
     textBoxControl.RequiredFieldText = "*required";
     textBoxControl.ErrorMsgForRequiredField = "*required";
     textBoxControl.RequiredFieldDisplay = ValidatorDisplay.Static;
     textBoxControl.ValidationGroup = "formbuilder";
 }

 pnlControls.Controls.Add(textBoxControl);

0 个答案:

没有答案