Amol
Amol

Reputation: 19

Custom server side validation in ASP.NET + VB.NET

This has not happened to me before, but for some reason server side validation events are not being triggered: I'm using Code below

<asp:CustomValidator runat="server" id="RefId" OnServerValidate="Ref_Id" ControlToValidate="txtRefId" ErrorMessage="Referral ID is Required." ></asp:CustomValidator>

When I fix the debugger on below code that time the code will not be triggered. plz check below code also.

Protected Sub Ref_Id(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
    Dim isPresent As String
    isPresent = MembershipManager.IsReferalApproved(Me.txtRefId.Text)
    If isPresent <> "" Then
        addReferralName()
        args.IsValid = True
    Else
        lblRefNotValid.Text = "Referral IDNO does not exist."
        lblRefNotValid.Visible = True
        Me.txtRefName.Text = ""
        args.IsValid = False
    End If
End Sub

Upvotes: 1

Views: 1170

Answers (2)

MrMagoo
MrMagoo

Reputation: 65

your custom validator's control should have the property ValidateEmptyText = True or the validation won't trigger on an empty textbox

Upvotes: 1

Tim Schmelter
Tim Schmelter

Reputation: 460158

Does your txtRefId Autopostback and CausesValidation?

Upvotes: 0

Related Questions