views:

34

answers:

2

Hi,

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
A: 

Does your txtRefId Autopostback and CausesValidation?

Tim Schmelter
I believe TextBox doesn't do any (Auto)Postback. Only CustomValidator does - because calls code-behind methods
abatishchev
You're on the wrong track. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.autopostback.aspxThe Validator does not post back. It is validated on the Codebehind when you do a Page.Validate()
Tim Schmelter
+1  A: 

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

MrMagoo
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.
Amol
Add back your controltovalidate. Put some default text in your textbox. See if the validation fires.
MrMagoo