Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following html:

ASP.NET
<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:

C#
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);
}


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.
Posted
Updated 31-Oct-11 1:49am
v5

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...
 
Share this answer
 
v2
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.
 
Share this answer
 
Comments
#realJSOP 29-Oct-11 9:01am    
Nope. The master page doesn't have a form tag.
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
 
Share this answer
 
Comments
#realJSOP 29-Oct-11 9:01am    
Nope - the master page doesn't have a form tag

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900