Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > validation not working properly

Reply
Thread Tools

validation not working properly

 
 
Stanley Glass
Guest
Posts: n/a
 
      01-14-2004
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


 
Reply With Quote
 
 
 
 
Stanley Glass
Guest
Posts: n/a
 
      01-14-2004
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

"Stanley Glass" <> wrote in message
news:...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2-digit year dates not validated properly during client validation =?Utf-8?B?UGFuYXlvdGlzIEtvdXZhcmFraXM=?= ASP .Net 0 12-02-2005 02:17 PM
onBlur validation not calling properly when press enterkey(not mouse click) raj ASP .Net 3 11-12-2005 06:31 AM
ASP.NET client-side validation working, but button click not working Alan Silver ASP .Net 1 08-02-2005 03:50 PM
ICS not working properly AuthorizedUser Wireless Networking 2 08-23-2004 04:46 AM
More American Graffiti: Properly Framed, Properly Scored? Scot Gardner DVD Video 0 09-02-2003 02:28 AM



Advertisments