CustomValidator control BUG

K

ken bus

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.
 
S

Scott M.

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


ken bus said:
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.
 
K

ken bus

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
 
S

Scott M.

ken bus said:
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
 
M

Mike Randall

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top