Home All Groups Group Topic Archive Search About
Author
14 Feb 2006 2:25 AM
Bob
Hi all,

I have a page where I am dynamically adding controls and validators.  The
required and compare validators are working fine.  The customvalidator does
not appear to be firing.  Here is the code I use for adding it:

  fldvalCustom = New UI.WebControls.CustomValidator
  With fldvalCustom
        .ID = "custcmp" & strName1
        .ControlToValidate = strName1
        .Display = ValidatorDisplay.Dynamic
        .ErrorMessage = dr("ParmName").ToString & " is not an integer."
        .Font.Bold = True
        .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
        .Text = "*"
   End With
   AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
   td.Controls.Add(fldvalCustom)

The CustomInt_ServerValidate routine validates both a single int and a comma
delimited list of ints - this is why a custom routine is required.  The
control that is validated is a HtmlControls.HtmlInputText.

I have trace statements in all of the routines and the custom routine is not
firing.  I also test for Page.IsValid within the submit server routine is its
true where is should be false.  I see the control in the control tree in the
trace page.

Does anyoe have any ideas?

Thank you, Bob

Author
14 Feb 2006 5:06 AM
Nathan Sokalski
I am not 100% sure about this, but I think that the Validator Controls only
work with the WebControls. Therefore, I would suggest using
WebControls.TextBox instead of HtmlControls.HtmlInputText. Other people may
know more about this than me, since I have never dynamically added
Validators.
--
Nathan Sokalski
njsokal***@hotmail.com
http://www.nathansokalski.com/

Show quoteHide quote
"Bob" <B**@discussions.microsoft.com> wrote in message
news:B075AB28-FBA6-404E-B573-71761D7C5C50@microsoft.com...
> Hi all,
>
> I have a page where I am dynamically adding controls and validators.  The
> required and compare validators are working fine.  The customvalidator
> does
> not appear to be firing.  Here is the code I use for adding it:
>
>  fldvalCustom = New UI.WebControls.CustomValidator
>  With fldvalCustom
>        .ID = "custcmp" & strName1
>        .ControlToValidate = strName1
>        .Display = ValidatorDisplay.Dynamic
>        .ErrorMessage = dr("ParmName").ToString & " is not an integer."
>        .Font.Bold = True
>        .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
>        .Text = "*"
>   End With
>   AddHandler fldvalCustom.ServerValidate, AddressOf
> CustomInt_ServerValidate
>   td.Controls.Add(fldvalCustom)
>
> The CustomInt_ServerValidate routine validates both a single int and a
> comma
> delimited list of ints - this is why a custom routine is required.  The
> control that is validated is a HtmlControls.HtmlInputText.
>
> I have trace statements in all of the routines and the custom routine is
> not
> firing.  I also test for Page.IsValid within the submit server routine is
> its
> true where is should be false.  I see the control in the control tree in
> the
> trace page.
>
> Does anyoe have any ideas?
>
> Thank you, Bob
Author
14 Feb 2006 1:52 PM
Bob
Hi Nathan,

The other validators are working fine.  I did switch the control to a
TextBox to test and the customvalidator still doesn't fire.

Show quoteHide quote
"Nathan Sokalski" wrote:

> I am not 100% sure about this, but I think that the Validator Controls only
> work with the WebControls. Therefore, I would suggest using
> WebControls.TextBox instead of HtmlControls.HtmlInputText. Other people may
> know more about this than me, since I have never dynamically added
> Validators.
> --
> Nathan Sokalski
> njsokal***@hotmail.com
> http://www.nathansokalski.com/
>
> "Bob" <B**@discussions.microsoft.com> wrote in message
> news:B075AB28-FBA6-404E-B573-71761D7C5C50@microsoft.com...
> > Hi all,
> >
> > I have a page where I am dynamically adding controls and validators.  The
> > required and compare validators are working fine.  The customvalidator
> > does
> > not appear to be firing.  Here is the code I use for adding it:
> >
> >  fldvalCustom = New UI.WebControls.CustomValidator
> >  With fldvalCustom
> >        .ID = "custcmp" & strName1
> >        .ControlToValidate = strName1
> >        .Display = ValidatorDisplay.Dynamic
> >        .ErrorMessage = dr("ParmName").ToString & " is not an integer."
> >        .Font.Bold = True
> >        .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
> >        .Text = "*"
> >   End With
> >   AddHandler fldvalCustom.ServerValidate, AddressOf
> > CustomInt_ServerValidate
> >   td.Controls.Add(fldvalCustom)
> >
> > The CustomInt_ServerValidate routine validates both a single int and a
> > comma
> > delimited list of ints - this is why a custom routine is required.  The
> > control that is validated is a HtmlControls.HtmlInputText.
> >
> > I have trace statements in all of the routines and the custom routine is
> > not
> > firing.  I also test for Page.IsValid within the submit server routine is
> > its
> > true where is should be false.  I see the control in the control tree in
> > the
> > trace page.
> >
> > Does anyoe have any ideas?
> >
> > Thank you, Bob
>
>
>
Author
14 Feb 2006 4:28 PM
Phillip Williams
During the serverValidate event that you set the
ServerValidateEventArgs.IsValid to either false or true. The defualt is true
if you do not set it either way.

I put your sample code to illustrate to you how you could have used the
RegularExpressionValidator instead:
http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
Show quoteHide quote
"Bob" wrote:

> Hi all,
>
> I have a page where I am dynamically adding controls and validators.  The
> required and compare validators are working fine.  The customvalidator does
> not appear to be firing.  Here is the code I use for adding it:
>
>   fldvalCustom = New UI.WebControls.CustomValidator
>   With fldvalCustom
>         .ID = "custcmp" & strName1
>         .ControlToValidate = strName1
>         .Display = ValidatorDisplay.Dynamic
>         .ErrorMessage = dr("ParmName").ToString & " is not an integer."
>         .Font.Bold = True
>         .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
>         .Text = "*"
>    End With
>    AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
>    td.Controls.Add(fldvalCustom)
>
> The CustomInt_ServerValidate routine validates both a single int and a comma
> delimited list of ints - this is why a custom routine is required.  The
> control that is validated is a HtmlControls.HtmlInputText.
>
> I have trace statements in all of the routines and the custom routine is not
> firing.  I also test for Page.IsValid within the submit server routine is its
> true where is should be false.  I see the control in the control tree in the
> trace page.
>
> Does anyoe have any ideas?
>
> Thank you, Bob
Author
14 Feb 2006 4:58 PM
Bob
Hi Phillip,

Here's the validate code.  It is validating a single integer or a comma
delimited list of integers:

    Private Sub CustomInt_ServerValidate(ByVal source As Object, ByVal args
As System.Web.UI.WebControls.ServerValidateEventArgs)
        Dim arr() As String
        Trace.Write("In CustomInt")
        If args.Value.IndexOf(",") > 0 Then
            arr = args.Value.Split(",")
            For i As Integer = LBound(arr) To UBound(arr)
                If IsNumeric(arr(i)) Then
                    Try
                        Dim x As Integer = CInt(arr(i))
                        args.IsValid = True
                    Catch ex As Exception
                        args.IsValid = False
                        Exit For
                    End Try
                Else
                    args.IsValid = False
                    Exit For
                End If
            Next
        Else
            '' assume single value
            If IsNumeric(args.Value) Then
                Try
                    Dim x As Integer = CInt(args.Value)
                    args.IsValid = True
                Catch ex As Exception
                    args.IsValid = False
                End Try
            Else
                args.IsValid = False
            End If
        End If

    End Sub


Thank you,

Bob

Show quoteHide quote
"Phillip Williams" wrote:

> During the serverValidate event that you set the
> ServerValidateEventArgs.IsValid to either false or true. The defualt is true
> if you do not set it either way.
>
> I put your sample code to illustrate to you how you could have used the
> RegularExpressionValidator instead:
> http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Bob" wrote:
>
> > Hi all,
> >
> > I have a page where I am dynamically adding controls and validators.  The
> > required and compare validators are working fine.  The customvalidator does
> > not appear to be firing.  Here is the code I use for adding it:
> >
> >   fldvalCustom = New UI.WebControls.CustomValidator
> >   With fldvalCustom
> >         .ID = "custcmp" & strName1
> >         .ControlToValidate = strName1
> >         .Display = ValidatorDisplay.Dynamic
> >         .ErrorMessage = dr("ParmName").ToString & " is not an integer."
> >         .Font.Bold = True
> >         .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
> >         .Text = "*"
> >    End With
> >    AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
> >    td.Controls.Add(fldvalCustom)
> >
> > The CustomInt_ServerValidate routine validates both a single int and a comma
> > delimited list of ints - this is why a custom routine is required.  The
> > control that is validated is a HtmlControls.HtmlInputText.
> >
> > I have trace statements in all of the routines and the custom routine is not
> > firing.  I also test for Page.IsValid within the submit server routine is its
> > true where is should be false.  I see the control in the control tree in the
> > trace page.
> >
> > Does anyoe have any ideas?
> >
> > Thank you, Bob
Author
14 Feb 2006 5:11 PM
Phillip Williams
I added your code to the demo:
http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx

It is still working.  Are you saying that it does not work on your PC? 
Which entry is not validating correctly if you try it on my website?
Show quoteHide quote
"Bob" wrote:

> Hi Phillip,
>
> Here's the validate code.  It is validating a single integer or a comma
> delimited list of integers:
>
>     Private Sub CustomInt_ServerValidate(ByVal source As Object, ByVal args
> As System.Web.UI.WebControls.ServerValidateEventArgs)
>         Dim arr() As String
>         Trace.Write("In CustomInt")
>         If args.Value.IndexOf(",") > 0 Then
>             arr = args.Value.Split(",")
>             For i As Integer = LBound(arr) To UBound(arr)
>                 If IsNumeric(arr(i)) Then
>                     Try
>                         Dim x As Integer = CInt(arr(i))
>                         args.IsValid = True
>                     Catch ex As Exception
>                         args.IsValid = False
>                         Exit For
>                     End Try
>                 Else
>                     args.IsValid = False
>                     Exit For
>                 End If
>             Next
>         Else
>             '' assume single value
>             If IsNumeric(args.Value) Then
>                 Try
>                     Dim x As Integer = CInt(args.Value)
>                     args.IsValid = True
>                 Catch ex As Exception
>                     args.IsValid = False
>                 End Try
>             Else
>                 args.IsValid = False
>             End If
>         End If
>
>     End Sub
>
>
> Thank you,
>
> Bob
>
> "Phillip Williams" wrote:
>
> > During the serverValidate event that you set the
> > ServerValidateEventArgs.IsValid to either false or true. The defualt is true
> > if you do not set it either way.
> >
> > I put your sample code to illustrate to you how you could have used the
> > RegularExpressionValidator instead:
> > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "Bob" wrote:
> >
> > > Hi all,
> > >
> > > I have a page where I am dynamically adding controls and validators.  The
> > > required and compare validators are working fine.  The customvalidator does
> > > not appear to be firing.  Here is the code I use for adding it:
> > >
> > >   fldvalCustom = New UI.WebControls.CustomValidator
> > >   With fldvalCustom
> > >         .ID = "custcmp" & strName1
> > >         .ControlToValidate = strName1
> > >         .Display = ValidatorDisplay.Dynamic
> > >         .ErrorMessage = dr("ParmName").ToString & " is not an integer."
> > >         .Font.Bold = True
> > >         .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
> > >         .Text = "*"
> > >    End With
> > >    AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
> > >    td.Controls.Add(fldvalCustom)
> > >
> > > The CustomInt_ServerValidate routine validates both a single int and a comma
> > > delimited list of ints - this is why a custom routine is required.  The
> > > control that is validated is a HtmlControls.HtmlInputText.
> > >
> > > I have trace statements in all of the routines and the custom routine is not
> > > firing.  I also test for Page.IsValid within the submit server routine is its
> > > true where is should be false.  I see the control in the control tree in the
> > > trace page.
> > >
> > > Does anyoe have any ideas?
> > >
> > > Thank you, Bob
Author
14 Feb 2006 5:32 PM
Bob
Hi Phillip,

It's not working here.  I am running this on a separate server.  However,
the code for building the page dynamically is occurring from the Page_Load
event, not from the Page_Init as in your example.  Could this be why it's not
working?

Show quoteHide quote
"Phillip Williams" wrote:

> I added your code to the demo:
> http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
>
> It is still working.  Are you saying that it does not work on your PC? 
> Which entry is not validating correctly if you try it on my website?
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Bob" wrote:
>
> > Hi Phillip,
> >
> > Here's the validate code.  It is validating a single integer or a comma
> > delimited list of integers:
> >
> >     Private Sub CustomInt_ServerValidate(ByVal source As Object, ByVal args
> > As System.Web.UI.WebControls.ServerValidateEventArgs)
> >         Dim arr() As String
> >         Trace.Write("In CustomInt")
> >         If args.Value.IndexOf(",") > 0 Then
> >             arr = args.Value.Split(",")
> >             For i As Integer = LBound(arr) To UBound(arr)
> >                 If IsNumeric(arr(i)) Then
> >                     Try
> >                         Dim x As Integer = CInt(arr(i))
> >                         args.IsValid = True
> >                     Catch ex As Exception
> >                         args.IsValid = False
> >                         Exit For
> >                     End Try
> >                 Else
> >                     args.IsValid = False
> >                     Exit For
> >                 End If
> >             Next
> >         Else
> >             '' assume single value
> >             If IsNumeric(args.Value) Then
> >                 Try
> >                     Dim x As Integer = CInt(args.Value)
> >                     args.IsValid = True
> >                 Catch ex As Exception
> >                     args.IsValid = False
> >                 End Try
> >             Else
> >                 args.IsValid = False
> >             End If
> >         End If
> >
> >     End Sub
> >
> >
> > Thank you,
> >
> > Bob
> >
> > "Phillip Williams" wrote:
> >
> > > During the serverValidate event that you set the
> > > ServerValidateEventArgs.IsValid to either false or true. The defualt is true
> > > if you do not set it either way.
> > >
> > > I put your sample code to illustrate to you how you could have used the
> > > RegularExpressionValidator instead:
> > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "Bob" wrote:
> > >
> > > > Hi all,
> > > >
> > > > I have a page where I am dynamically adding controls and validators.  The
> > > > required and compare validators are working fine.  The customvalidator does
> > > > not appear to be firing.  Here is the code I use for adding it:
> > > >
> > > >   fldvalCustom = New UI.WebControls.CustomValidator
> > > >   With fldvalCustom
> > > >         .ID = "custcmp" & strName1
> > > >         .ControlToValidate = strName1
> > > >         .Display = ValidatorDisplay.Dynamic
> > > >         .ErrorMessage = dr("ParmName").ToString & " is not an integer."
> > > >         .Font.Bold = True
> > > >         .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
> > > >         .Text = "*"
> > > >    End With
> > > >    AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
> > > >    td.Controls.Add(fldvalCustom)
> > > >
> > > > The CustomInt_ServerValidate routine validates both a single int and a comma
> > > > delimited list of ints - this is why a custom routine is required.  The
> > > > control that is validated is a HtmlControls.HtmlInputText.
> > > >
> > > > I have trace statements in all of the routines and the custom routine is not
> > > > firing.  I also test for Page.IsValid within the submit server routine is its
> > > > true where is should be false.  I see the control in the control tree in the
> > > > trace page.
> > > >
> > > > Does anyoe have any ideas?
> > > >
> > > > Thank you, Bob
Author
14 Feb 2006 5:43 PM
Phillip Williams
It could be; depending on whether in your real application the control to be
validated is created dynamically or not.  But for this simple demo, where the
validation is executed against a control that was declaratively defined on
the form, placing the code in the page_load would not affect it much.  Here
it is:
http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator2.aspx
Show quoteHide quote
"Bob" wrote:

> Hi Phillip,
>
> It's not working here.  I am running this on a separate server.  However,
> the code for building the page dynamically is occurring from the Page_Load
> event, not from the Page_Init as in your example.  Could this be why it's not
> working?
>
> "Phillip Williams" wrote:
>
> > I added your code to the demo:
> > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> >
> > It is still working.  Are you saying that it does not work on your PC? 
> > Which entry is not validating correctly if you try it on my website?
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "Bob" wrote:
> >
> > > Hi Phillip,
> > >
> > > Here's the validate code.  It is validating a single integer or a comma
> > > delimited list of integers:
> > >
> > >     Private Sub CustomInt_ServerValidate(ByVal source As Object, ByVal args
> > > As System.Web.UI.WebControls.ServerValidateEventArgs)
> > >         Dim arr() As String
> > >         Trace.Write("In CustomInt")
> > >         If args.Value.IndexOf(",") > 0 Then
> > >             arr = args.Value.Split(",")
> > >             For i As Integer = LBound(arr) To UBound(arr)
> > >                 If IsNumeric(arr(i)) Then
> > >                     Try
> > >                         Dim x As Integer = CInt(arr(i))
> > >                         args.IsValid = True
> > >                     Catch ex As Exception
> > >                         args.IsValid = False
> > >                         Exit For
> > >                     End Try
> > >                 Else
> > >                     args.IsValid = False
> > >                     Exit For
> > >                 End If
> > >             Next
> > >         Else
> > >             '' assume single value
> > >             If IsNumeric(args.Value) Then
> > >                 Try
> > >                     Dim x As Integer = CInt(args.Value)
> > >                     args.IsValid = True
> > >                 Catch ex As Exception
> > >                     args.IsValid = False
> > >                 End Try
> > >             Else
> > >                 args.IsValid = False
> > >             End If
> > >         End If
> > >
> > >     End Sub
> > >
> > >
> > > Thank you,
> > >
> > > Bob
> > >
> > > "Phillip Williams" wrote:
> > >
> > > > During the serverValidate event that you set the
> > > > ServerValidateEventArgs.IsValid to either false or true. The defualt is true
> > > > if you do not set it either way.
> > > >
> > > > I put your sample code to illustrate to you how you could have used the
> > > > RegularExpressionValidator instead:
> > > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > > > --
> > > > HTH,
> > > > Phillip Williams
> > > > http://www.societopia.net
> > > > http://www.webswapp.com
> > > >
> > > >
> > > > "Bob" wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > > I have a page where I am dynamically adding controls and validators.  The
> > > > > required and compare validators are working fine.  The customvalidator does
> > > > > not appear to be firing.  Here is the code I use for adding it:
> > > > >
> > > > >   fldvalCustom = New UI.WebControls.CustomValidator
> > > > >   With fldvalCustom
> > > > >         .ID = "custcmp" & strName1
> > > > >         .ControlToValidate = strName1
> > > > >         .Display = ValidatorDisplay.Dynamic
> > > > >         .ErrorMessage = dr("ParmName").ToString & " is not an integer."
> > > > >         .Font.Bold = True
> > > > >         .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
> > > > >         .Text = "*"
> > > > >    End With
> > > > >    AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
> > > > >    td.Controls.Add(fldvalCustom)
> > > > >
> > > > > The CustomInt_ServerValidate routine validates both a single int and a comma
> > > > > delimited list of ints - this is why a custom routine is required.  The
> > > > > control that is validated is a HtmlControls.HtmlInputText.
> > > > >
> > > > > I have trace statements in all of the routines and the custom routine is not
> > > > > firing.  I also test for Page.IsValid within the submit server routine is its
> > > > > true where is should be false.  I see the control in the control tree in the
> > > > > trace page.
> > > > >
> > > > > Does anyoe have any ideas?
> > > > >
> > > > > Thank you, Bob
Author
14 Feb 2006 6:16 PM
Bob
Hi Phillip,

The regular expression works great!  How would I change the
ValidationExpress to validate a single or comma delimited list of double/real?

Show quoteHide quote
"Phillip Williams" wrote:

> It could be; depending on whether in your real application the control to be
> validated is created dynamically or not.  But for this simple demo, where the
> validation is executed against a control that was declaratively defined on
> the form, placing the code in the page_load would not affect it much.  Here
> it is:
> http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator2.aspx
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Bob" wrote:
>
> > Hi Phillip,
> >
> > It's not working here.  I am running this on a separate server.  However,
> > the code for building the page dynamically is occurring from the Page_Load
> > event, not from the Page_Init as in your example.  Could this be why it's not
> > working?
> >
> > "Phillip Williams" wrote:
> >
> > > I added your code to the demo:
> > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > >
> > > It is still working.  Are you saying that it does not work on your PC? 
> > > Which entry is not validating correctly if you try it on my website?
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "Bob" wrote:
> > >
> > > > Hi Phillip,
> > > >
> > > > Here's the validate code.  It is validating a single integer or a comma
> > > > delimited list of integers:
> > > >
> > > >     Private Sub CustomInt_ServerValidate(ByVal source As Object, ByVal args
> > > > As System.Web.UI.WebControls.ServerValidateEventArgs)
> > > >         Dim arr() As String
> > > >         Trace.Write("In CustomInt")
> > > >         If args.Value.IndexOf(",") > 0 Then
> > > >             arr = args.Value.Split(",")
> > > >             For i As Integer = LBound(arr) To UBound(arr)
> > > >                 If IsNumeric(arr(i)) Then
> > > >                     Try
> > > >                         Dim x As Integer = CInt(arr(i))
> > > >                         args.IsValid = True
> > > >                     Catch ex As Exception
> > > >                         args.IsValid = False
> > > >                         Exit For
> > > >                     End Try
> > > >                 Else
> > > >                     args.IsValid = False
> > > >                     Exit For
> > > >                 End If
> > > >             Next
> > > >         Else
> > > >             '' assume single value
> > > >             If IsNumeric(args.Value) Then
> > > >                 Try
> > > >                     Dim x As Integer = CInt(args.Value)
> > > >                     args.IsValid = True
> > > >                 Catch ex As Exception
> > > >                     args.IsValid = False
> > > >                 End Try
> > > >             Else
> > > >                 args.IsValid = False
> > > >             End If
> > > >         End If
> > > >
> > > >     End Sub
> > > >
> > > >
> > > > Thank you,
> > > >
> > > > Bob
> > > >
> > > > "Phillip Williams" wrote:
> > > >
> > > > > During the serverValidate event that you set the
> > > > > ServerValidateEventArgs.IsValid to either false or true. The defualt is true
> > > > > if you do not set it either way.
> > > > >
> > > > > I put your sample code to illustrate to you how you could have used the
> > > > > RegularExpressionValidator instead:
> > > > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > > > > --
> > > > > HTH,
> > > > > Phillip Williams
> > > > > http://www.societopia.net
> > > > > http://www.webswapp.com
> > > > >
> > > > >
> > > > > "Bob" wrote:
> > > > >
> > > > > > Hi all,
> > > > > >
> > > > > > I have a page where I am dynamically adding controls and validators.  The
> > > > > > required and compare validators are working fine.  The customvalidator does
> > > > > > not appear to be firing.  Here is the code I use for adding it:
> > > > > >
> > > > > >   fldvalCustom = New UI.WebControls.CustomValidator
> > > > > >   With fldvalCustom
> > > > > >         .ID = "custcmp" & strName1
> > > > > >         .ControlToValidate = strName1
> > > > > >         .Display = ValidatorDisplay.Dynamic
> > > > > >         .ErrorMessage = dr("ParmName").ToString & " is not an integer."
> > > > > >         .Font.Bold = True
> > > > > >         .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
> > > > > >         .Text = "*"
> > > > > >    End With
> > > > > >    AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
> > > > > >    td.Controls.Add(fldvalCustom)
> > > > > >
> > > > > > The CustomInt_ServerValidate routine validates both a single int and a comma
> > > > > > delimited list of ints - this is why a custom routine is required.  The
> > > > > > control that is validated is a HtmlControls.HtmlInputText.
> > > > > >
> > > > > > I have trace statements in all of the routines and the custom routine is not
> > > > > > firing.  I also test for Page.IsValid within the submit server routine is its
> > > > > > true where is should be false.  I see the control in the control tree in the
> > > > > > trace page.
> > > > > >
> > > > > > Does anyoe have any ideas?
> > > > > >
> > > > > > Thank you, Bob
Author
14 Feb 2006 8:04 PM
Phillip Williams
Try this for a number(6,2)
ValidationExpression ="^((\+|-)?\d{1,6}(\.\d{1,2})?\b\,?)*$"
Show quoteHide quote
"Bob" wrote:

> Hi Phillip,
>
> The regular expression works great!  How would I change the
> ValidationExpress to validate a single or comma delimited list of double/real?
>
> "Phillip Williams" wrote:
>
> > It could be; depending on whether in your real application the control to be
> > validated is created dynamically or not.  But for this simple demo, where the
> > validation is executed against a control that was declaratively defined on
> > the form, placing the code in the page_load would not affect it much.  Here
> > it is:
> > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator2.aspx
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "Bob" wrote:
> >
> > > Hi Phillip,
> > >
> > > It's not working here.  I am running this on a separate server.  However,
> > > the code for building the page dynamically is occurring from the Page_Load
> > > event, not from the Page_Init as in your example.  Could this be why it's not
> > > working?
> > >
> > > "Phillip Williams" wrote:
> > >
> > > > I added your code to the demo:
> > > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > > >
> > > > It is still working.  Are you saying that it does not work on your PC? 
> > > > Which entry is not validating correctly if you try it on my website?
> > > > --
> > > > HTH,
> > > > Phillip Williams
> > > > http://www.societopia.net
> > > > http://www.webswapp.com
> > > >
> > > >
> > > > "Bob" wrote:
> > > >
> > > > > Hi Phillip,
> > > > >
> > > > > Here's the validate code.  It is validating a single integer or a comma
> > > > > delimited list of integers:
> > > > >
> > > > >     Private Sub CustomInt_ServerValidate(ByVal source As Object, ByVal args
> > > > > As System.Web.UI.WebControls.ServerValidateEventArgs)
> > > > >         Dim arr() As String
> > > > >         Trace.Write("In CustomInt")
> > > > >         If args.Value.IndexOf(",") > 0 Then
> > > > >             arr = args.Value.Split(",")
> > > > >             For i As Integer = LBound(arr) To UBound(arr)
> > > > >                 If IsNumeric(arr(i)) Then
> > > > >                     Try
> > > > >                         Dim x As Integer = CInt(arr(i))
> > > > >                         args.IsValid = True
> > > > >                     Catch ex As Exception
> > > > >                         args.IsValid = False
> > > > >                         Exit For
> > > > >                     End Try
> > > > >                 Else
> > > > >                     args.IsValid = False
> > > > >                     Exit For
> > > > >                 End If
> > > > >             Next
> > > > >         Else
> > > > >             '' assume single value
> > > > >             If IsNumeric(args.Value) Then
> > > > >                 Try
> > > > >                     Dim x As Integer = CInt(args.Value)
> > > > >                     args.IsValid = True
> > > > >                 Catch ex As Exception
> > > > >                     args.IsValid = False
> > > > >                 End Try
> > > > >             Else
> > > > >                 args.IsValid = False
> > > > >             End If
> > > > >         End If
> > > > >
> > > > >     End Sub
> > > > >
> > > > >
> > > > > Thank you,
> > > > >
> > > > > Bob
> > > > >
> > > > > "Phillip Williams" wrote:
> > > > >
> > > > > > During the serverValidate event that you set the
> > > > > > ServerValidateEventArgs.IsValid to either false or true. The defualt is true
> > > > > > if you do not set it either way.
> > > > > >
> > > > > > I put your sample code to illustrate to you how you could have used the
> > > > > > RegularExpressionValidator instead:
> > > > > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > > > > > --
> > > > > > HTH,
> > > > > > Phillip Williams
> > > > > > http://www.societopia.net
> > > > > > http://www.webswapp.com
> > > > > >
> > > > > >
> > > > > > "Bob" wrote:
> > > > > >
> > > > > > > Hi all,
> > > > > > >
> > > > > > > I have a page where I am dynamically adding controls and validators.  The
> > > > > > > required and compare validators are working fine.  The customvalidator does
> > > > > > > not appear to be firing.  Here is the code I use for adding it:
> > > > > > >
> > > > > > >   fldvalCustom = New UI.WebControls.CustomValidator
> > > > > > >   With fldvalCustom
> > > > > > >         .ID = "custcmp" & strName1
> > > > > > >         .ControlToValidate = strName1
> > > > > > >         .Display = ValidatorDisplay.Dynamic
> > > > > > >         .ErrorMessage = dr("ParmName").ToString & " is not an integer."
> > > > > > >         .Font.Bold = True
> > > > > > >         .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
> > > > > > >         .Text = "*"
> > > > > > >    End With
> > > > > > >    AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
> > > > > > >    td.Controls.Add(fldvalCustom)
> > > > > > >
> > > > > > > The CustomInt_ServerValidate routine validates both a single int and a comma
> > > > > > > delimited list of ints - this is why a custom routine is required.  The
> > > > > > > control that is validated is a HtmlControls.HtmlInputText.
> > > > > > >
> > > > > > > I have trace statements in all of the routines and the custom routine is not
> > > > > > > firing.  I also test for Page.IsValid within the submit server routine is its
> > > > > > > true where is should be false.  I see the control in the control tree in the
> > > > > > > trace page.
> > > > > > >
> > > > > > > Does anyoe have any ideas?
> > > > > > >
> > > > > > > Thank you, Bob
Author
16 Feb 2006 7:34 PM
Bob
Thanks Phillip!  Its working great.

Show quoteHide quote
"Phillip Williams" wrote:

> Try this for a number(6,2)
> ValidationExpression ="^((\+|-)?\d{1,6}(\.\d{1,2})?\b\,?)*$"
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "Bob" wrote:
>
> > Hi Phillip,
> >
> > The regular expression works great!  How would I change the
> > ValidationExpress to validate a single or comma delimited list of double/real?
> >
> > "Phillip Williams" wrote:
> >
> > > It could be; depending on whether in your real application the control to be
> > > validated is created dynamically or not.  But for this simple demo, where the
> > > validation is executed against a control that was declaratively defined on
> > > the form, placing the code in the page_load would not affect it much.  Here
> > > it is:
> > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator2.aspx
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "Bob" wrote:
> > >
> > > > Hi Phillip,
> > > >
> > > > It's not working here.  I am running this on a separate server.  However,
> > > > the code for building the page dynamically is occurring from the Page_Load
> > > > event, not from the Page_Init as in your example.  Could this be why it's not
> > > > working?
> > > >
> > > > "Phillip Williams" wrote:
> > > >
> > > > > I added your code to the demo:
> > > > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > > > >
> > > > > It is still working.  Are you saying that it does not work on your PC? 
> > > > > Which entry is not validating correctly if you try it on my website?
> > > > > --
> > > > > HTH,
> > > > > Phillip Williams
> > > > > http://www.societopia.net
> > > > > http://www.webswapp.com
> > > > >
> > > > >
> > > > > "Bob" wrote:
> > > > >
> > > > > > Hi Phillip,
> > > > > >
> > > > > > Here's the validate code.  It is validating a single integer or a comma
> > > > > > delimited list of integers:
> > > > > >
> > > > > >     Private Sub CustomInt_ServerValidate(ByVal source As Object, ByVal args
> > > > > > As System.Web.UI.WebControls.ServerValidateEventArgs)
> > > > > >         Dim arr() As String
> > > > > >         Trace.Write("In CustomInt")
> > > > > >         If args.Value.IndexOf(",") > 0 Then
> > > > > >             arr = args.Value.Split(",")
> > > > > >             For i As Integer = LBound(arr) To UBound(arr)
> > > > > >                 If IsNumeric(arr(i)) Then
> > > > > >                     Try
> > > > > >                         Dim x As Integer = CInt(arr(i))
> > > > > >                         args.IsValid = True
> > > > > >                     Catch ex As Exception
> > > > > >                         args.IsValid = False
> > > > > >                         Exit For
> > > > > >                     End Try
> > > > > >                 Else
> > > > > >                     args.IsValid = False
> > > > > >                     Exit For
> > > > > >                 End If
> > > > > >             Next
> > > > > >         Else
> > > > > >             '' assume single value
> > > > > >             If IsNumeric(args.Value) Then
> > > > > >                 Try
> > > > > >                     Dim x As Integer = CInt(args.Value)
> > > > > >                     args.IsValid = True
> > > > > >                 Catch ex As Exception
> > > > > >                     args.IsValid = False
> > > > > >                 End Try
> > > > > >             Else
> > > > > >                 args.IsValid = False
> > > > > >             End If
> > > > > >         End If
> > > > > >
> > > > > >     End Sub
> > > > > >
> > > > > >
> > > > > > Thank you,
> > > > > >
> > > > > > Bob
> > > > > >
> > > > > > "Phillip Williams" wrote:
> > > > > >
> > > > > > > During the serverValidate event that you set the
> > > > > > > ServerValidateEventArgs.IsValid to either false or true. The defualt is true
> > > > > > > if you do not set it either way.
> > > > > > >
> > > > > > > I put your sample code to illustrate to you how you could have used the
> > > > > > > RegularExpressionValidator instead:
> > > > > > > http://www.webswapp.com/codesamples/aspnet20/regularExpressionValidator.aspx
> > > > > > > --
> > > > > > > HTH,
> > > > > > > Phillip Williams
> > > > > > > http://www.societopia.net
> > > > > > > http://www.webswapp.com
> > > > > > >
> > > > > > >
> > > > > > > "Bob" wrote:
> > > > > > >
> > > > > > > > Hi all,
> > > > > > > >
> > > > > > > > I have a page where I am dynamically adding controls and validators.  The
> > > > > > > > required and compare validators are working fine.  The customvalidator does
> > > > > > > > not appear to be firing.  Here is the code I use for adding it:
> > > > > > > >
> > > > > > > >   fldvalCustom = New UI.WebControls.CustomValidator
> > > > > > > >   With fldvalCustom
> > > > > > > >         .ID = "custcmp" & strName1
> > > > > > > >         .ControlToValidate = strName1
> > > > > > > >         .Display = ValidatorDisplay.Dynamic
> > > > > > > >         .ErrorMessage = dr("ParmName").ToString & " is not an integer."
> > > > > > > >         .Font.Bold = True
> > > > > > > >         .Font.Size = New FontUnit(New Unit(14, UnitType.Point))
> > > > > > > >         .Text = "*"
> > > > > > > >    End With
> > > > > > > >    AddHandler fldvalCustom.ServerValidate, AddressOf CustomInt_ServerValidate
> > > > > > > >    td.Controls.Add(fldvalCustom)
> > > > > > > >
> > > > > > > > The CustomInt_ServerValidate routine validates both a single int and a comma
> > > > > > > > delimited list of ints - this is why a custom routine is required.  The
> > > > > > > > control that is validated is a HtmlControls.HtmlInputText.
> > > > > > > >
> > > > > > > > I have trace statements in all of the routines and the custom routine is not
> > > > > > > > firing.  I also test for Page.IsValid within the submit server routine is its
> > > > > > > > true where is should be false.  I see the control in the control tree in the
> > > > > > > > trace page.
> > > > > > > >
> > > > > > > > Does anyoe have any ideas?
> > > > > > > >
> > > > > > > > Thank you, Bob