服务器端CustomValidator无法验证

服务器端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.

我无法弄清楚CustomValidator的问题所在,因此我使用以下命令设置了正则表达式验证器正则表达式字符串:

.{30}.*

这样就可以了...
I couldn''t figure out what was wrong with the CustomValidator, so I setup a regex validator with the following regex string:

.{30}.*

That does the trick...


您好,亲爱的我刚刚复制了您的代码并在我的虚拟项目中进行了测试.
一切都很好.

所以我在您的.aspx代码中发现了什么
您正在使用contenholder.
多数民众赞成表示您拥有母版页.
母版页已具有表单标记.

而您错过的是您再次使用了表单标签.
请检查它,然后从您的内容页面中删除表单标签.
Hi dear i have just copied your code and just tested in my dummy project.
Every thing worked fine.

so what i found that in your .aspx code
you are using contenholder.
thats means you have master page.
A master page already have a form tag.

and what you missed is you have again used form tag.
Please check it and remove form tag from your content page.


亲爱的朋友,

只需删除表单标签.使用MasterPage时将存在一个表单标签.在内容占位符中,您将使用另一个表单标签.您删除该内容占位符表单标签.然后您对其进行检查. >

问候,

Anilkumar.D
Dear Friend,

Just You Remove the Form Tag.Your Using MasterPage in that one Form Tag will be There.In content Place Holder your using another form tag.You Remove that Content Place Holder Form Tag.Then You check it.It works fine.


Regards,

Anilkumar.D