开发者

Creating RequiredFieldValidator via Code Behind

开发者 https://www.devze.com 2022-12-10 17:44 出处:网络
i want to create a validatior via code behind.But although i create it,it doesnt fire when postback occurs.I craete validator in Page\'s Onload event.What can be reason?Here is my code.

i want to create a validatior via code behind.But although i create it,it doesnt fire when postback occurs.I craete validator in Page's Onload event.What can be reason?Here is my code.

Public Sub Validate(ByVal p_Page As Page, ByRef p_AssignedControl As System.Web.UI.WebControls.WebControl, ByVal p_Message As String)

    Dim v_VCALLOUT As New AjaxControlToolkit.ValidatorCalloutExtender

    Dim r_VALIDATOR As New System.Web.UI.WebControls.RequiredFieldValidator
    Dim placeHolder As PlaceHolder = p_Page.FindControl("Vld")


    With r_VALIDATOR

        .ID = "r_" & p_AssignedControl.ID
        .ControlToValidate = p_AssignedControl.ID
        .Display = ValidatorDisplay.None
        .ErrorMessage = p_Message
        .Font.Name = "Verdana"
        .Font.Size = FontSize.XSmall

    End With

    With v_VCALLOUT

        .ID = "v_" & r_VALIDATOR.ID
  开发者_JAVA技巧      '.CssClass = "highlight"
        .HighlightCssClass = "highlight"
        .WarningIconImageUrl = "~/images/warning.gif"
        .CloseImageUrl = "~/images/close.gif"
        .TargetControlID = r_VALIDATOR.ID
        .Enabled = True

    End With

    placeHolder.Controls.Add(v_VCALLOUT)
    placeHolder.Controls.Add(r_VALIDATOR)


End Sub


First thought: (from MSDN)

None The validation message is never displayed inline.

Do you have a Validation Summary?

Second thought:

try to create your validators in the Page_Init event.


I found reason.I call Validate Sub if page.IsPostpact=False.If i call Validate Sub in every postback,it works great.

0

精彩评论

暂无评论...
验证码 换一张
取 消