validation not working properly

S

Stanley Glass

Hello all,
I have a control that I am building that adds two validation controls to the
control heirarchy like so:
Code:
'setup and register client-side validation
If Not Page.IsClientScriptBlockRegistered(Me.ID.ToString &
"_ValidationClientScript") Then
Dim js As New System.Text.StringBuilder
js.Append("<script language=""vbscript"">" & vbCrLf)
js.Append("<!--" & vbCrLf)
js.Append("Sub " & Me.ID.ToString & "_ClientValidate(ByVal source, ByVal
arguments)" & vbCrLf)
js.Append("If Len(replace(arguments.Value,""_"","""")) = " & _length & "
Then" & vbCrLf)
js.Append("arguments.IsValid = True" & vbCrLf)
js.Append("Else" & vbCrLf)
js.Append("arguments.IsValid = False" & vbCrLf)
js.Append("End If" & vbCrLf)
js.Append("End Sub" & vbCrLf)
js.Append("' -->" & vbCrLf)
js.Append("</script>" & vbCrLf)
Page.RegisterClientScriptBlock(Me.ID.ToString & "_ValidationClientScript",
js.ToString)
js = Nothing
End If
val.EnableClientScript = _enableclientscript
val.Display = ValidatorDisplay.Dynamic
val.ErrorMessage = _errormsg
val.ControlToValidate = txt.ID.ToString
val.ID = "validator"

val1.ClientValidationFunction = Me.ID.ToString & "_ClientValidate"
val1.ControlToValidate = txt.ID.ToString
val1.Display = ValidatorDisplay.Dynamic
val1.EnableClientScript = _enableclientscript
val1.ErrorMessage = "Invalid Format!"
AddHandler val1.ServerValidate, AddressOf ServerValidate
Me.Controls.Add(val1)
Me.Controls.Add(val)

Now everything works fine when I try to post the data except that after the
post is done I get the "Invalid Format!" error message. The information
posted fine and if I try to put in an invalid format the validation works
fine. The problem just seems to be after the post and the building of the
page and I am not sure why. Anyone know a possible reason why it would be
checking the validation again? Of course if I don't clear the textbox that
it is validating and leave the properly formatted value in it I still get
that same error and yet I can just keep submitting the form and since the
control is actually valid the form is posted.

-Stanley
 
S

Stanley Glass

Ok I commented out the AddHandler for the second validation and it seems to
work correctly now. It seems that was causing the issue.

-Stanley
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top