validation not working properly

Discussion in 'ASP .Net Building Controls' started by Stanley Glass, Jan 14, 2004.

  1. 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
     
    Stanley Glass, Jan 14, 2004
    #1
    1. Advertising

  2. 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
    >
    >
     
    Stanley Glass, Jan 14, 2004
    #2
    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. Aaron Powell
    Replies:
    0
    Views:
    1,206
    Aaron Powell
    Jul 24, 2003
  2. Jasper
    Replies:
    0
    Views:
    493
    Jasper
    Jun 28, 2004
  3. Alan Silver
    Replies:
    1
    Views:
    3,789
    Alan Silver
    Aug 2, 2005
  4. raj
    Replies:
    3
    Views:
    2,434
  5. =?Utf-8?B?UGFuYXlvdGlzIEtvdXZhcmFraXM=?=

    2-digit year dates not validated properly during client validation

    =?Utf-8?B?UGFuYXlvdGlzIEtvdXZhcmFraXM=?=, Dec 2, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    559
    =?Utf-8?B?UGFuYXlvdGlzIEtvdXZhcmFraXM=?=
    Dec 2, 2005
Loading...

Share This Page