服务器端CustomValidator无法验证

我有以下html:

I have the following html:

<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolder1" Runat="Server">
    <form id="Form1" runat="server">
        <table style="width:100%;">
            <tr>
                <td valign="top">
                    Message Content (text only)
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" 

					        ControlToValidate="tbContent" 

                                                runat="server" 

                                                Display="Dynamic" 

                                                ErrorMessage="REQUIRED" />
                    <asp:CustomValidator ID="CustomValidator1" 

                                         ControlToValidate="tbContent" 

                                         runat="server" 

                                         EnableClientScript="false" 

                                         OnServerValidate="validate_Content" 

                                         ValidateEmptyText="true"  

                                         ErrorMessage="INVALID" 

                                         Display="Dynamic" />
                </td>
                <td>
                    <asp:TextBox ID="tbContent" 

                                 runat="server" 

                                 style="resize:none;" 

                                 Width="98%" 

                                 Height="20em" 

                                 TextMode="MultiLine"></asp:TextBox>
                </td>
            </tr>
        </table>
        <asp:Button ID="ButtonSubmit" 

                    Text="Submit" 

                    runat="server" 

                    CausesValidation="true" 

                    OnClick="click_Submit" ></asp:Button>
    </form>
</asp:Content>



以及以下代码:



And the following code-behind:

protected void click_Submit(object sender, EventArgs args)
{
    Page.Validate();
    if (Page.IsValid)
    {
    }
    else
    {
    }
}

protected void validate_Content(object sender, ServerValidateEventArgs e)
{
    e.IsValid = (e.Value.Length >= 30);
}



CustomValidator未验证.我添加了RequiredFieldValidator只是为了确保验证器可以正常工作.请注意以下内容:

0)我不想在客户端进行验证,因此不必理会建议.

1)RequiredFieldValidator实际上正在按您期望的方式工作.

2)我完全了解ValidateEmptyText属性应该消除对RequiredFieldValidator的需求这一事实,但是正如我说的那样,CustomValidator事件似乎没有触发.

3)我已经尝试过不指定要验证的控件,并且它仍然不会触发.

我很茫然.我已经尝试了在Google上发现的所有我认为适用的内容,但没有任何改变结果.

编辑=====================

仍在寻找答案.



The CustomValidator is not validating. I added the RequiredFieldValidator just to make sure the validators were working at all. Please note the following:

0) I do NOT want to validate on the client side, so don''t bother suggesting it.

1) The RequiredFieldValidator is in fact working as you would expect.

2) I am fully aware of the fact that the ValidateEmptyText property is supposed to eliminate the need for the RequiredFieldValidator, but as I said, the CustomValidator event doesn''t appear to fire.

3) I already tried not specifying a control to validate, and it STILL doesn''t fire.

I''m at a loss. I''ve tried everything I found on google that I thought was applicable, and nothing has changed the result.

EDIT =======================

Still looking for an answer to this.



 1 条回答