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.
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.
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.
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.
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.
Remember to set this property on the CustomValidator...
ValidateEmptyText="True"
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With