473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Custom Validator to validate certain items checked in a checkboxli

If possible, how can I use a custom validator to check (client side) that if
a certain value was checked in a checkboxlist? So, if they checked "great" or
"good", comments are not required and if they checked "not so great" or
"awful", comments would be required before allowing the page to post.
Aug 10 '06 #1
3 1163
Handle the ServerValidate method of your CustomValidator control as follows.
Set the args.IsValid equal to True if everything tests to be correct,
otherwise set it false.
Private Sub CustomValidator1_ServerValidate(ByVal source As
System.Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
Try
If chkGreat.Checked Or chkGood.Checked Then
args.IsValid = True
ElseIf chkNotSoGreat.Checked Or chkAwful.Checked Then
args.IsValid = (txtComments.Text.Trim() <"")
Else
args.IsValid = False
End If
Catch ex As Exception
'whatever
End Try
End Sub

"Mike Collins" wrote:
If possible, how can I use a custom validator to check (client side) that if
a certain value was checked in a checkboxlist? So, if they checked "great" or
"good", comments are not required and if they checked "not so great" or
"awful", comments would be required before allowing the page to post.
Aug 10 '06 #2
Oh, and if you're specifically looking for client-side validation, if it
involves more than one control, you'll have to manually write some javascript
validation routine and call it on form submission.

"Mike Collins" wrote:
If possible, how can I use a custom validator to check (client side) that if
a certain value was checked in a checkboxlist? So, if they checked "great" or
"good", comments are not required and if they checked "not so great" or
"awful", comments would be required before allowing the page to post.
Aug 10 '06 #3
Thanks...that helps with the server side and will help me think out the rest.

"Keith" wrote:
Handle the ServerValidate method of your CustomValidator control as follows.
Set the args.IsValid equal to True if everything tests to be correct,
otherwise set it false.
Private Sub CustomValidator1_ServerValidate(ByVal source As
System.Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
Try
If chkGreat.Checked Or chkGood.Checked Then
args.IsValid = True
ElseIf chkNotSoGreat.Checked Or chkAwful.Checked Then
args.IsValid = (txtComments.Text.Trim() <"")
Else
args.IsValid = False
End If
Catch ex As Exception
'whatever
End Try
End Sub

"Mike Collins" wrote:
If possible, how can I use a custom validator to check (client side) that if
a certain value was checked in a checkboxlist? So, if they checked "great" or
"good", comments are not required and if they checked "not so great" or
"awful", comments would be required before allowing the page to post.
Aug 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stephan Bour | last post by:
Hi, I need to validate a text box in a datagrid nested inside a datalist. All I need is to validate that any text is entered in the textbox. However, a requiredfieldvalidator would not do because...
5
by: Richard Payne | last post by:
Hi This is probably a newbie question but I can't seem to find a clear answer to the problem I have. I have created a Custom Validator control on my webform that works fine, but when I put...
9
by: Alex Shirley | last post by:
Hi there I’m simply trying to check for a blank or empty value in a textbox on my webform. In this instance I do not want to use a requiredfieldvalidator, I want to use a customvalidator (as I...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
1
by: Elie Medeiros via .NET 247 | last post by:
Hi there, I have written a custom validator function to validate a datefrom a user-filled field. The function tries to parse the dateand if it can't, sets (serverValidateEventArgs)e.IsValid...
5
by: Mattyw | last post by:
Hi, I'm relatively new to Web Forms, I have been using Required Field Validators and Regular Expression Validators on a Web Form I am developing and everything works as expected using Visual...
2
by: Martin | last post by:
I am writing a custom validator by extending CustomValidator in order to validate three fields as follows: If checkbox true then textboxA and textboxB must have data in. The problem I am...
0
by: tsw_mik | last post by:
I have created a custom control. It has: -label -button -list of textboxes -list of dropdownlists. I want to use a custom validator to perform some validation, but somehow I can't fo it. The...
0
by: Jay Douglas | last post by:
Hello all, I'm in need of a custom validator that: 1). Runs server side code using ajax through a client validate function 2). Client validate function does not set args.IsValid until the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.