CustomValidator control BUG

Discussion in 'ASP .Net Web Controls' started by ken bus, Aug 1, 2004.

  1. ken bus

    ken bus Guest

    If this is intended behavior the documentation is rotten!
    One customvalidator in an error state with one or more other noncustom validators in a like state will cause unexpected behavior.
    One would think that this customVal would act like the other val controls but this doesn't occur. The customVal will only report its error if all the other val controls are not reporting errors whether or not one is using a summary control. Only when all the other val controls have had their errors corrected, will the customVal behave as expected. One would think it should report its message along with the others in the summary control.
     
    ken bus, Aug 1, 2004
    #1
    1. Advertising

  2. ken bus

    Scott M. Guest

    Let's see your code. We can't help you unless you give us specifics.


    "ken bus" <> wrote in message
    news:...
    > If this is intended behavior the documentation is rotten!
    > One customvalidator in an error state with one or more other noncustom

    validators in a like state will cause unexpected behavior.
    > One would think that this customVal would act like the other val controls

    but this doesn't occur. The customVal will only report its error if all the
    other val controls are not reporting errors whether or not one is using a
    summary control. Only when all the other val controls have had their errors
    corrected, will the customVal behave as expected. One would think it should
    report its message along with the others in the summary control.
     
    Scott M., Aug 1, 2004
    #2
    1. Advertising

  3. ken bus

    ken bus Guest

    To reproduce the bug do the following:
    1) only use the validators for the server side; no client support of validation.
    2) place a textbox,textbox1, and a customvalidator, val1, that is bound to the textbox1 on to the web form; another validator of some kind, val2, that is bound to another textbox, textbox2 on to the same web form.
    3) produce an invalid condition in textbox2 so that val2 is notifying the invalid condition and val1 will not display its notification of an invalid input for textbox1 even if there is input in textbox1.
    4) produce a postback and only val2 will display its invalid input condition.
    5) val1 will behave as expected if textbox2's invalid input is corrected and val2 is not notifying anymore.

    NOTE: that the server-side event handler must be setup correctly since it does fire when textbox2's invalid state for input is cleared.

    Code behind follows:
    Public Class TempTest
    Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents val1 As System.Web.UI.WebControls.CustomValidator
    Protected WithEvents val2 As System.Web.UI.WebControls.RequiredFieldValidator

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub
    Protected Sub TextValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
    args.IsValid = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    val1.Validate()
    End Sub
    End Class



    "Peter Blum" wrote:

    > I agree that we need the code. I saw some code from you in another thread.
    > Overall it looked good although it lacks any client-side code. That means it
    > will validate only when the server side code runs validation.
    >
    > The CustomValidator is just another generic Validator control to the core
    > client and server side code that validate a page. When you submit, the code
    > goes through every validator that is not marked disabled (its Enabled
    > property = false) and validates it. It does not stop on any particular
    > validator. There are no dependencies between validators. This is true on
    > both client and server side.
    >
    > There are a couple of common problems users have with CustomValidators:
    > 1. Expect client-side validation when no code was written
    > 2. Do not correctly setup the ServerValidate event handler so it never gets
    > called on the server side
    > 3. Want it to fire when there is a blank textbox. It will not unless you do
    > not assign anything to ControlToValidate.
    >
    > --- Peter Blum
    > www.PeterBlum.com
    > Email:
    > Creator of "Professional Validation And More" at
    > http://www.peterblum.com/vam/home.aspx
    >
    > "ken bus" <> wrote in message
    > news:...
    > > If this is intended behavior the documentation is rotten!
    > > One customvalidator in an error state with one or more other noncustom

    > validators in a like state will cause unexpected behavior.
    > > One would think that this customVal would act like the other val controls

    > but this doesn't occur. The customVal will only report its error if all the
    > other val controls are not reporting errors whether or not one is using a
    > summary control. Only when all the other val controls have had their errors
    > corrected, will the customVal behave as expected. One would think it should
    > report its message along with the others in the summary control.
    >
    >
    >
     
    ken bus, Aug 2, 2004
    #3
  4. ken bus

    Scott M. Guest

    "ken bus" <> wrote in message
    news:...
    > To reproduce the bug do the following:
    > 1) only use the validators for the server side; no client support of

    validation.

    But stop right there..... This is a little like saying "Remove one wheel
    from your automobile and you'll find that your car doesn't drive correctly!"

    > 2) place a textbox,textbox1, and a customvalidator, val1, that is bound to

    the textbox1 on to the web form; another validator of some kind, val2, that
    is bound to another textbox, textbox2 on to the same web form.
    > 3) produce an invalid condition in textbox2 so that val2 is notifying the

    invalid condition and val1 will not display its notification of an invalid
    input for textbox1 even if there is input in textbox1.

    Of course it won't, you didn't include any code for server-side validation
    of val1 so how could it validate itself and decide it failed?

    > 4) produce a postback and only val2 will display its invalid input

    condition.
    > 5) val1 will behave as expected if textbox2's invalid input is corrected

    and val2 is not notifying anymore.

    That's not what I get. When I add valid data to val2, its error message
    goes away and val1 sits there as it had before.


    The point is this, you aren't using these validators correctly and so it's
    not surprising that you are encountering anomolies. A custom validator
    needs to have custom server-side code written so that it knows what to do
    when the time comes, you didn't include any of that in your example, so of
    course val1 does not report any invalid conditions.


    >
    > NOTE: that the server-side event handler must be setup correctly since it

    does fire when textbox2's invalid state for input is cleared.
    >
    > Code behind follows:
    > Public Class TempTest
    > Inherits System.Web.UI.Page
    >
    > #Region " Web Form Designer Generated Code "
    >
    > 'This call is required by the Web Form Designer.
    > <System.Diagnostics.DebuggerStepThrough()> Private Sub

    InitializeComponent()
    >
    > End Sub
    > Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    > Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    > Protected WithEvents val1 As System.Web.UI.WebControls.CustomValidator
    > Protected WithEvents val2 As

    System.Web.UI.WebControls.RequiredFieldValidator
    >
    > 'NOTE: The following placeholder declaration is required by the Web

    Form Designer.
    > 'Do not delete or move it.
    > Private designerPlaceholderDeclaration As System.Object
    >
    > Private Sub Page_Init(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MyBase.Init
    > 'CODEGEN: This method call is required by the Web Form Designer
    > 'Do not modify it using the code editor.
    > InitializeComponent()
    > End Sub
    >
    > #End Region
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MyBase.Load
    > 'Put user code to initialize the page here
    > End Sub
    > Protected Sub TextValidate(ByVal source As System.Object, ByVal args As

    System.Web.UI.WebControls.ServerValidateEventArgs)
    > args.IsValid = False
    > End Sub
    >
    > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles Button1.Click
    > val1.Validate()
    > End Sub
    > End Class
    >
    >
    >
    > "Peter Blum" wrote:
    >
    > > I agree that we need the code. I saw some code from you in another

    thread.
    > > Overall it looked good although it lacks any client-side code. That

    means it
    > > will validate only when the server side code runs validation.
    > >
    > > The CustomValidator is just another generic Validator control to the

    core
    > > client and server side code that validate a page. When you submit, the

    code
    > > goes through every validator that is not marked disabled (its Enabled
    > > property = false) and validates it. It does not stop on any particular
    > > validator. There are no dependencies between validators. This is true on
    > > both client and server side.
    > >
    > > There are a couple of common problems users have with CustomValidators:
    > > 1. Expect client-side validation when no code was written
    > > 2. Do not correctly setup the ServerValidate event handler so it never

    gets
    > > called on the server side
    > > 3. Want it to fire when there is a blank textbox. It will not unless you

    do
    > > not assign anything to ControlToValidate.
    > >
    > > --- Peter Blum
    > > www.PeterBlum.com
    > > Email:
    > > Creator of "Professional Validation And More" at
    > > http://www.peterblum.com/vam/home.aspx
    > >
    > > "ken bus" <> wrote in message
    > > news:...
    > > > If this is intended behavior the documentation is rotten!
    > > > One customvalidator in an error state with one or more other noncustom

    > > validators in a like state will cause unexpected behavior.
    > > > One would think that this customVal would act like the other val

    controls
    > > but this doesn't occur. The customVal will only report its error if all

    the
    > > other val controls are not reporting errors whether or not one is using

    a
    > > summary control. Only when all the other val controls have had their

    errors
    > > corrected, will the customVal behave as expected. One would think it

    should
    > > report its message along with the others in the summary control.
    > >
    > >
    > >
     
    Scott M., Aug 2, 2004
    #4
  5. ken bus

    Mike Randall Guest

    I have the exact same results as Ken. I have a large page with about 40
    regular validators and 4 custom ones (server side only). The custom
    validators will only fire after the regular error conditions have been
    cleared.

    I use a validation summary and end up with 2 pass validation.

    Not good.


    "Peter Blum" <> wrote in message
    news:%239VrWW%...
    >I agree that we need the code. I saw some code from you in another thread.
    > Overall it looked good although it lacks any client-side code. That means
    > it
    > will validate only when the server side code runs validation.
    >
    > The CustomValidator is just another generic Validator control to the core
    > client and server side code that validate a page. When you submit, the
    > code
    > goes through every validator that is not marked disabled (its Enabled
    > property = false) and validates it. It does not stop on any particular
    > validator. There are no dependencies between validators. This is true on
    > both client and server side.
    >
    > There are a couple of common problems users have with CustomValidators:
    > 1. Expect client-side validation when no code was written
    > 2. Do not correctly setup the ServerValidate event handler so it never
    > gets
    > called on the server side
    > 3. Want it to fire when there is a blank textbox. It will not unless you
    > do
    > not assign anything to ControlToValidate.
    >
    > --- Peter Blum
    > www.PeterBlum.com
    > Email:
    > Creator of "Professional Validation And More" at
    > http://www.peterblum.com/vam/home.aspx
    >
    > "ken bus" <> wrote in message
    > news:...
    >> If this is intended behavior the documentation is rotten!
    >> One customvalidator in an error state with one or more other noncustom

    > validators in a like state will cause unexpected behavior.
    >> One would think that this customVal would act like the other val controls

    > but this doesn't occur. The customVal will only report its error if all
    > the
    > other val controls are not reporting errors whether or not one is using a
    > summary control. Only when all the other val controls have had their
    > errors
    > corrected, will the customVal behave as expected. One would think it
    > should
    > report its message along with the others in the summary control.
    >
    >
     
    Mike Randall, Jul 19, 2005
    #5
    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. George Ter-Saakov

    CustomValidator bug?

    George Ter-Saakov, Jul 22, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    606
    George Ter-Saakov
    Jul 22, 2003
  2. Jim Heavey

    CustomValidator Control

    Jim Heavey, Dec 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    359
  3. =?Utf-8?B?Vmk=?=

    CustomValidator Control

    =?Utf-8?B?Vmk=?=, Oct 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    371
    Scott Allen
    Oct 21, 2004
  4. Dan Sikorsky
    Replies:
    1
    Views:
    5,896
    Dan Sikorsky
    Feb 17, 2005
  5. avp
    Replies:
    1
    Views:
    21,723
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Dec 16, 2005
Loading...

Share This Page