1

我正在创建动态控件,我想添加必填字段验证器,下面是我的代码,但必填字段验证器没有触发。我在 page_init 中添加控件。任何人都知道为什么这段代码不起作用。当我添加单个控件时,同一段代码正在工作。当我尝试添加多行控件时它不起作用。

ctrls.Add(New LiteralControl("<br />"))
                ctrls.Add(CreateRequiredFieldValidatorMR(StrControlID.ToString, "Required field."))


Private Function CreateRequiredFieldValidatorMR(ByVal strControlID As String, ByVal ErrorMessage As String) As RequiredFieldValidator
    Return CreateRequiredFieldValidatorMR(strControlID, ErrorMessage, String.Empty)
End Function

Private Function CreateRequiredFieldValidatorMR(ByVal strControlID As String, ByVal ErrorMessage As String, ByVal InitialValue As String) As RequiredFieldValidator
    Dim rfv As New RequiredFieldValidator
    rfv.ID = "ReqVal_" & strControlID
    rfv.ControlToValidate = strControlID
    rfv.Display = ValidatorDisplay.Dynamic
    rfv.ErrorMessage = ErrorMessage
    rfv.InitialValue = InitialValue
    rfv.ValidationGroup = "ReqGrp_" + strControlID
    rfv.ForeColor = Drawing.Color.Red
    rfv.Font.Bold = True
    Return rfv
End Function
4

0 回答 0