Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Validator not firing

I realize there are lots of similar posts, however I have not found one that has worked for me unfortunately. Basically, I have an asp:customvalidator that I am trying to add to a validationgroup with other validators so that all error messages appear in the same alert. Here is the customvalidator

<asp:TextBox runat="server" ID="txtVideo1Url"  Columns="20" Width="98%" />
<asp:CustomValidator runat="server" ID="valURL1" ControlToValidate="txtVideo1Url" OnServerValidate="txtVideo1Url_ServerValidate" Display="None" ValidationGroup="submission" />

and here is the event

    protected void txtVideo1Url_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        e.IsValid = false;
        valURL1.Text = "FAIL!";
    }

The event isn't firing at all and I have no idea why. Once I can get the event firing I can put some actual logic into it, lol

UPDATE: I've noticed that I am now able to get the event firing, however the validationsummary is set to display all errors in a messagebox and this error isn't getting added to the messagebox.

like image 355
Mark Highfield Avatar asked Jun 28 '13 15:06

Mark Highfield


People also ask

What methods should you implement for your custom validator?

A Validator implementation must contain a constructor, a set of accessor methods for any attributes on the tag, and a validate method, which overrides the validate method of the Validator interface.

What does custom validator mean?

The CustomValidator control is a separate control from the input control it validates, which allows you to control where the validation message is displayed. Validation controls always perform validation on the server.

How do I create a custom validator?

in order to implement a custom validation directive, we need to implement the Validator interface, which only has the validate method. the validate method is going to call the validation creation function, and pass the control reference (the password control in this case) to the validator.

What is custom field validator in asp net?

CustomValidator. The CustomValidator control allows writing application specific custom validation routines for both the client side and the server side validation. The client side validation is accomplished through the ClientValidationFunction property.


2 Answers

Remember to set this property on the CustomValidator...

ValidateEmptyText="True"
like image 176
Remotec Avatar answered Nov 17 '22 11:11

Remotec


You need to set the CausesValidation property of the TextBox to true, like this:

<asp:TextBox runat="server" ID="txtVideo1Url"  Columns="20" Width="98%" CausesValidation="true" />
like image 27
Karl Anderson Avatar answered Nov 17 '22 09:11

Karl Anderson