473,811 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
<ValidationProp erty("Validatio nValue")> _
Public Class ValidifiableChe ckBox : Inherits
System.Web.UI.W ebControls.Chec kBox
Private mValidationTrue Value As String = Boolean.TrueStr ing

Public Property ValidationTrueV alue() As String
Get
Return mValidationTrue Value
End Get
Set(ByVal value As String)
mValidationTrue Value = value
End Set
End Property
Public ReadOnly Property ValidationValue () As String
Get
If Me.Checked Then
Return mValidationTrue Value
Else
Return System.String.E mpty
End If
End Get
End Property

End Class
Apr 27 '06 #1
2 1524
Why would you bother extending the checkbox? Just put the following code in
the CustomControl's ServerValidate eventhandler:
If mycheckbox.Chec ked 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********@hotm ail.com
http://www.nathansokalski.com/

"Martin" <Ma****@discuss ions.microsoft. com> wrote in message
news:42******** *************** ***********@mic rosoft.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.
<ValidationProp erty("Validatio nValue")> _
Public Class ValidifiableChe ckBox : Inherits
System.Web.UI.W ebControls.Chec kBox
Private mValidationTrue Value As String = Boolean.TrueStr ing

Public Property ValidationTrueV alue() As String
Get
Return mValidationTrue Value
End Get
Set(ByVal value As String)
mValidationTrue Value = value
End Set
End Property
Public ReadOnly Property ValidationValue () As String
Get
If Me.Checked Then
Return mValidationTrue Value
Else
Return System.String.E mpty
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.Chec ked 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********@hotm ail.com
http://www.nathansokalski.com/

"Martin" <Ma****@discuss ions.microsoft. com> wrote in message
news:42******** *************** ***********@mic rosoft.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.
<ValidationProp erty("Validatio nValue")> _
Public Class ValidifiableChe ckBox : Inherits
System.Web.UI.W ebControls.Chec kBox
Private mValidationTrue Value As String = Boolean.TrueStr ing

Public Property ValidationTrueV alue() As String
Get
Return mValidationTrue Value
End Get
Set(ByVal value As String)
mValidationTrue Value = value
End Set
End Property
Public ReadOnly Property ValidationValue () As String
Get
If Me.Checked Then
Return mValidationTrue Value
Else
Return System.String.E mpty
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
1286
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 OnServerValidate procedure is only called if both the Required and RegularExpression validators are successfully met. However, when I upload the page to my live website, if I enter an invalid value in the textbox (i.e. one that doesn't meet the...
8
7840
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 VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle "http://msdn.microsoft.com/library/default.asp?url=/library/en-...
5
2931
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 Studio.NET 2003 and VB code behind. I have a radio button and textbox, and basically i need the textbox to be required based on the user selecting "Yes" from the radio button. I've read through the newsgroups and found that a Custom Validator
2
1796
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 other validators on the page. I specified the name of the Javascript function with the ClientValidationFunction attribute of the custom validator, and it is being called fine. However, if the validator returns false (ie bad
1
1201
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 column. User can select multiple checkboxes and there's 1 submit button that will process allr ecords that have been checked. I don't know how to make the validator to work without putting the gird in edit mode, and that can only be done one row at...
9
3141
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 lot of research in the areas of XHTML and WAI compliance, and am attempting to come up with a recommendation for our product in terms of standards level compliance. Ideally, I would like to be at XHTML 1.0 Strict. However, in my reading I have...
3
8255
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, even if I force the customvalidator to validate by invoking its validate() method after a button is clicked: cvCustomValidator_ServerValidate(object source, system.Web.UI.WebControls.ServerValidateEventArgs args) <== doesn't get
0
1577
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 code looks like this: public class ColumnSelector : Panel {
4
2116
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 required validator. I need to have a validator for my custom control, but don't know how to do this. I added a CustomValidator to the form, but in design mode, my custom
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.