473,386 Members | 1,726 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,386 software developers and data experts.

Custom validator and Checkboxes

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 having is that whether the checkbox is ticked or not it
returns the value "on" to my validator code. This is all using the ideas of
DanielHac as at http://www.codeproject.com/aspnet/Mu...dValidator.asp &
he suggests extending the checkbox control as below. Despite doing this I
still ahvev the porblem.

Any ideas?

-------------------------------------------------------------
'Replacement for standard checkbox.
'This allows the checked property to be read by validation controls.
'Standard microsoft support for clienside validation of a checkbox is broken.
<ValidationProperty("ValidationValue")> _
Public Class ValidifiableCheckBox : Inherits
System.Web.UI.WebControls.CheckBox
Private mValidationTrueValue As String = Boolean.TrueString

Public Property ValidationTrueValue() As String
Get
Return mValidationTrueValue
End Get
Set(ByVal value As String)
mValidationTrueValue = value
End Set
End Property
Public ReadOnly Property ValidationValue() As String
Get
If Me.Checked Then
Return mValidationTrueValue
Else
Return System.String.Empty
End If
End Get
End Property

End Class
Apr 27 '06 #1
2 1507
Why would you bother extending the checkbox? Just put the following code in
the CustomControl's ServerValidate eventhandler:
If mycheckbox.Checked Then
If mytextbox1.Text = "" Or mytextbox2.Text = "" Then
args.IsValid = False
Else
args.IsValid = True
End If
Else
args.IsValid = True
End If
If you have some reason for wanting to extend the CheckBox that I am
missing, let me know, but I see know reason to do that in your case. Good
Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Martin" <Ma****@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
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 having is that whether the checkbox is ticked or not it
returns the value "on" to my validator code. This is all using the ideas
of
DanielHac as at
http://www.codeproject.com/aspnet/Mu...dValidator.asp &
he suggests extending the checkbox control as below. Despite doing this I
still ahvev the porblem.

Any ideas?

-------------------------------------------------------------
'Replacement for standard checkbox.
'This allows the checked property to be read by validation controls.
'Standard microsoft support for clienside validation of a checkbox is
broken.
<ValidationProperty("ValidationValue")> _
Public Class ValidifiableCheckBox : Inherits
System.Web.UI.WebControls.CheckBox
Private mValidationTrueValue As String = Boolean.TrueString

Public Property ValidationTrueValue() As String
Get
Return mValidationTrueValue
End Get
Set(ByVal value As String)
mValidationTrueValue = value
End Set
End Property
Public ReadOnly Property ValidationValue() As String
Get
If Me.Checked Then
Return mValidationTrueValue
Else
Return System.String.Empty
End If
End Get
End Property

End Class

Apr 28 '06 #2
I should have said - that works server side but I just canlt get it to work
client side. Reserach suggested that the clinet side validation stuff
doesnlt work proerly for checkboxes (see URL in my last posting) and that one
needs to extend the checkbx as I have done. But I canlt get either the
extended or normal checkbox to work client side - when converted to string it
always returns the value "on" regardless of whether the box is ticked or not

"Nathan Sokalski" wrote:
Why would you bother extending the checkbox? Just put the following code in
the CustomControl's ServerValidate eventhandler:
If mycheckbox.Checked Then
If mytextbox1.Text = "" Or mytextbox2.Text = "" Then
args.IsValid = False
Else
args.IsValid = True
End If
Else
args.IsValid = True
End If
If you have some reason for wanting to extend the CheckBox that I am
missing, let me know, but I see know reason to do that in your case. Good
Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Martin" <Ma****@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
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 having is that whether the checkbox is ticked or not it
returns the value "on" to my validator code. This is all using the ideas
of
DanielHac as at
http://www.codeproject.com/aspnet/Mu...dValidator.asp &
he suggests extending the checkbox control as below. Despite doing this I
still ahvev the porblem.

Any ideas?

-------------------------------------------------------------
'Replacement for standard checkbox.
'This allows the checked property to be read by validation controls.
'Standard microsoft support for clienside validation of a checkbox is
broken.
<ValidationProperty("ValidationValue")> _
Public Class ValidifiableCheckBox : Inherits
System.Web.UI.WebControls.CheckBox
Private mValidationTrueValue As String = Boolean.TrueString

Public Property ValidationTrueValue() As String
Get
Return mValidationTrueValue
End Get
Set(ByVal value As String)
mValidationTrueValue = value
End Set
End Property
Public ReadOnly Property ValidationValue() As String
Get
If Me.Checked Then
Return mValidationTrueValue
Else
Return System.String.Empty
End If
End Get
End Property

End Class


Apr 28 '06 #3

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

Similar topics

2
by: Mike P | last post by:
I have a Custom validator that has ControlToValidate set to a textbox that also has a Required and RegularExpression validator. When I run the webpage on my machine the custom validator...
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...
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: Alan Silver | last post by:
Hello, I have a custom validator on my page, and have the server-side code working fine. I want to add a client-side funtion as well, but am not sure how to wire it in so that it works with the...
1
by: valeria007 | last post by:
Hello! Is it possible to have a validator in a datagrid's ItemTemplate part of the column and NOT in the EditTemplatePart? I know it works in Edit Mode, but this is a datagrid with a checkbox...
9
by: wardy1975 | last post by:
Hi All, Looking for a little expert advice on a few web standards issues. I am currently trying to understand the impact of web standards for a web application I work with. I have been doing a...
3
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
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...
4
by: Rick | last post by:
Hello, I built a composite web control that has a textbox and a date control. added my custom control on a webform where there are other standard controls. Each control on the form has a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.