简体   繁体   中英

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.

请记住在CustomValidator上设置此属性...

ValidateEmptyText="True"

您需要将TextBoxCausesValidation属性设置为true ,如下所示:

<asp:TextBox runat="server" ID="txtVideo1Url"  Columns="20" Width="98%" CausesValidation="true" />

您必须将ValidationGroup =“submission”添加到将触发回发的ASP.NET控件。

CustomValidators don't fire if other Validators in your ASPx are not validating. You may need to force a Page.Validate("something"), with your specific validation group. I suggest look at OnTextChanged event to force a page validate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM