1

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
1
  • You can use e.Value instead of Me.txtRefId.Text because they are the same. CustomValidator takes attribute ValidationProperty value from ControlToValidate. For TexBox this is Text property. Commented Jul 2, 2010 at 12:54

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I add ValidateEmptyText = True in <asp:/> but still serverside validation not fired,The validation fire only when I eliminate Controltovalidate from this asp tag.but my validation function call every time.
Add back your controltovalidate. Put some default text in your textbox. See if the validation fires.
0

Does your txtRefId Autopostback and CausesValidation?

2 Comments

I believe TextBox doesn't do any (Auto)Postback. Only CustomValidator does - because calls code-behind methods
You're on the wrong track. msdn.microsoft.com/en-us/library/… The Validator does not post back. It is validated on the Codebehind when you do a Page.Validate()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.