Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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);
}
 
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 22-Oct-11 4:27am
Edited 31-Oct-11 1:49am
v5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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...
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Comments
   
Nope. The master page doesn't have a form tag.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Comments
   
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
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 192
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,077
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 4 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100