CustomValidator bug?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Ter-Saakov

    #1

    CustomValidator bug?

    Hi.

    I am fighting the CustomValidator strange behavior for second day already.
    I created some test project which is only to reproduce the problem.

    1. I created UserControl which has an only a Custom Validator
    2. in UserControl::Pa ge_Load i set
    CustomValidator 1.IsValid = false;

    3. I insert the User Control into the page and have a submit button there.


    So when i run the project it shows me errors from CustomValidator (because
    IsValid set to false)
    But when i click submit button there is no error shown and Page.IsValid
    returns true.


    Am i missing something? Where should i set CustomValidator 1.IsValid = false;
    so the Page.IsValid would be set to false as well?


    Thanks.
    George.


  • George Ter-Saakov

    #2
    Re: CustomValidator bug?

    Got to the bottom of it.
    It turned out that I must provide handler CustomValidator .ServerValidate and
    set args.IsValid = false in it.

    Otherwise the IsValid is reset to true.

    Which is not very good design. I would say if ServerValidate event is not
    handled then IsValid must stay as is.

    Thanks.
    George.


    "George Ter-Saakov" <we@hotmail.com > wrote in message
    news:ugr99JFUDH A.1552@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hi.
    >
    > I am fighting the CustomValidator strange behavior for second day already.
    > I created some test project which is only to reproduce the problem.
    >
    > 1. I created UserControl which has an only a Custom Validator
    > 2. in UserControl::Pa ge_Load i set
    > CustomValidator 1.IsValid = false;
    >
    > 3. I insert the User Control into the page and have a submit button there.
    >
    >
    > So when i run the project it shows me errors from CustomValidator (because
    > IsValid set to false)
    > But when i click submit button there is no error shown and Page.IsValid
    > returns true.
    >
    >
    > Am i missing something? Where should i set CustomValidator 1.IsValid =[/color]
    false;[color=blue]
    > so the Page.IsValid would be set to false as well?
    >
    >
    > Thanks.
    > George.
    >
    >[/color]


    Comment

    • Hans Kesting

      #3
      Re: CustomValidator bug?


      "George Ter-Saakov" <we@hotmail.com > wrote in message
      news:ugr99JFUDH A.1552@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi.
      >
      > I am fighting the CustomValidator strange behavior for second day already.
      > I created some test project which is only to reproduce the problem.
      >
      > 1. I created UserControl which has an only a Custom Validator
      > 2. in UserControl::Pa ge_Load i set
      > CustomValidator 1.IsValid = false;
      >
      > 3. I insert the User Control into the page and have a submit button there.
      >
      >
      > So when i run the project it shows me errors from CustomValidator (because
      > IsValid set to false)
      > But when i click submit button there is no error shown and Page.IsValid
      > returns true.
      >
      >
      > Am i missing something? Where should i set CustomValidator 1.IsValid =[/color]
      false;[color=blue]
      > so the Page.IsValid would be set to false as well?
      >
      >
      > Thanks.
      > George.
      >
      >[/color]

      To implement a CustomValidator you need to handle the ServerValidate event.


      private void CustomValidator 1_ServerValidat e(object source,
      System.Web.UI.W ebControls.Serv erValidateEvent Args args)
      {
      args.IsValid = false;
      }


      Hans Kesting


      Comment

      Working...