CustomValidator not working in FormView

Discussion in 'ASP .Net Web Controls' started by J. Cairn, Sep 16, 2007.

  1. J. Cairn

    J. Cairn Guest

    I have tried everything and can't get the validation code to fire.
    Code is below. I have simplified some of it to test it.


    Here is the CustomValidator (it is in the InsertItemTemplate of my
    FormView):
    -----------------------------------------------------------------------------------------------------------------------------------------------
    <asp:CustomValidator ID="CustomValidator1" runat="server"
    ControlToValidate="DropDownList2"
    ErrorMessage="You must make a lunch choice." ValidateEmptyText="True"
    OnServerValidate="ValidatorTest_ServerValidate"></
    asp:CustomValidator></td>
    -----------------------------------------------------------------------------------------------------------------------------------------------


    Here is the custom validation code. For testing, I set it to
    automatically "fail".
    -----------------------------------------------------------------------------------------------------------------------------------------------
    Sub ValidatorTest_ServerValidate(ByVal sender As Object, ByVal
    args As ServerValidateEventArgs)
    args.IsValid = False
    End Sub
    -----------------------------------------------------------------------------------------------------------------------------------------------


    Here is the code on the Submit button.
    -----------------------------------------------------------------------------------------------------------------------------------------------
    Sub btnSubmit_Click(sender as Object, e as EventArgs)
    If Page.IsValid then
    Response.Write("Page is valid")
    Else
    Response.Write("Page is not valid.")
    End If
    End Sub
    -----------------------------------------------------------------------------------------------------------------------------------------------

    When I run the page, I get a message saying "Page is valid" which
    would indicate that the validation code is not even running. What am I
    doing wrong?
    J. Cairn, Sep 16, 2007
    #1
    1. Advertising

  2. J. Cairn

    Forum Guest

    Hi, tested and it seems fine, can you provide more code?


    "J. Cairn" <> schreef in bericht
    news:...
    >I have tried everything and can't get the validation code to fire.
    > Code is below. I have simplified some of it to test it.
    >
    >
    > Here is the CustomValidator (it is in the InsertItemTemplate of my
    > FormView):
    > -----------------------------------------------------------------------------------------------------------------------------------------------
    > <asp:CustomValidator ID="CustomValidator1" runat="server"
    > ControlToValidate="DropDownList2"
    > ErrorMessage="You must make a lunch choice." ValidateEmptyText="True"
    > OnServerValidate="ValidatorTest_ServerValidate"></
    > asp:CustomValidator></td>
    > -----------------------------------------------------------------------------------------------------------------------------------------------
    >
    >
    > Here is the custom validation code. For testing, I set it to
    > automatically "fail".
    > -----------------------------------------------------------------------------------------------------------------------------------------------
    > Sub ValidatorTest_ServerValidate(ByVal sender As Object, ByVal
    > args As ServerValidateEventArgs)
    > args.IsValid = False
    > End Sub
    > -----------------------------------------------------------------------------------------------------------------------------------------------
    >
    >
    > Here is the code on the Submit button.
    > -----------------------------------------------------------------------------------------------------------------------------------------------
    > Sub btnSubmit_Click(sender as Object, e as EventArgs)
    > If Page.IsValid then
    > Response.Write("Page is valid")
    > Else
    > Response.Write("Page is not valid.")
    > End If
    > End Sub
    > -----------------------------------------------------------------------------------------------------------------------------------------------
    >
    > When I run the page, I get a message saying "Page is valid" which
    > would indicate that the validation code is not even running. What am I
    > doing wrong?
    >
    Forum, Sep 20, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad

    CustomValidator not working

    tshad, Nov 11, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,554
    tshad
    Nov 12, 2004
  2. theresa
    Replies:
    2
    Views:
    721
    theresa
    Sep 12, 2007
  3. Mo

    Server side CustomValidator and FormView

    Mo, Mar 2, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    139
  4. Glen

    CustomValidator not working in FireFox

    Glen, Jun 27, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    669
    Walter Wang [MSFT]
    Jun 29, 2006
  5. Dabbler

    customvalidator using clientside script in FormView

    Dabbler, Apr 13, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    170
    Dabbler
    Apr 13, 2006
Loading...

Share This Page