Thanks for your response, Whilst waiting for a response I've already investigated the custom
validator, however, when I try to get the "args.Value" in my clientside code I always get the value
"on" regardless of state.
Here is my code from my custom validator can you spot any errors?
protected void Page_Load(object sender, EventArgs e){
string csValidFunc = "function ClientValidateVCB(source, args){" + Environment.NewLine +
" args.IsValid = (args.Value == '" + bool.TrueString + "');" + Environment.NewLine +
"}";
ClientScript.RegisterClientScriptBlock(this.GetType(), "ClientValidateVCB", csValidFunc, true);
}
protected void cvAgree_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = (args.Value == bool.TrueString);
}
> Well a checkbox is basically either checked or unchecked so having the
> special case were the user has to check the checkbox were likely not MS top
[quoted text clipped - 45 lines]
>>
>>Why did microsoft not make the CheckBox control validatable?
Steven Cheng[MSFT] - 14 Dec 2007 03:35 GMT
Hi MC,
As for ASP.NET CheckBox control, it does be a particular one which can not
be used directly by any built-in validators except the CustomValidator
control. Also, even for custom validator, you still need to particularly
customize the validation function(client script). Here is a forum article
which provide an example on how to use custom valiator to validate checkbox:
#Control 'CheckBox1' referenced by the ControlToValidate property
http://www.syncfusion.com/FAQ/aspnet/WEB_c18c.aspx#q464q
and another article provide good example on impleneting custom validator:
#Implementing custom validation in ASP.NET with the CustomValidator class
http://www.kuam.com/techtalk/customvalidatorclass.htm
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>Date: Thu, 13 Dec 2007 13:08:24 +0000
>From: mc <mc@community.nospam>
[quoted text clipped - 68 lines]
>>>
>>>Why did microsoft not make the CheckBox control validatable?
mc - 14 Dec 2007 09:23 GMT
Thanks for that, this was the solution I stumbled across myself. However I was hoping that I would
be able to work with args.Value, and have clean generic functions is there not anything I could do
with my inherited control to make it correctly validatable?
Is there a bug or issue within asp.net which means the "Team" couldn't make the CheckBox validatable?
Thanks
MC
> Hi MC,
>
[quoted text clipped - 133 lines]
>>>>
>>>>Why did microsoft not make the CheckBox control validatable?
Steven Cheng[MSFT] - 17 Dec 2007 03:15 GMT
Thanks for your reply MC,
So far this seems a limitation due to the existing CheckBox control's
implementation. I suggest you post this issue to the product feedback
center so that the product team can receive feedback on this:
http://connect.microsoft.com/feedback/default.aspx?SiteID=210
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>Date: Fri, 14 Dec 2007 09:23:14 +0000
>From: mc <mc@community.nospam>
[quoted text clipped - 34 lines]
>>
>> This posting is provided "AS IS" with no warranties, and confers no rights.
Patrice - 14 Dec 2007 08:07 GMT
IMO the problem is that the checkbox input control doesn"t have a value
property. What is the bool variable you are referring to ?
IMO you should use somewhere the checked property (and you'll have to get
this value by yourself).
--
Patrice
> Thanks for your response, Whilst waiting for a response I've already
> investigated the custom validator, however, when I try to get the
[quoted text clipped - 69 lines]
>>>
>>>Why did microsoft not make the CheckBox control validatable?
mc - 14 Dec 2007 10:40 GMT
bool is not a variable. It is a reference to the static field "TrueString" of the bool type. See
here for a full explanation.
http://msdn2.microsoft.com/en-us/library/system.boolean.truestring(VS.71).aspx
The theory of my first post is that the control below, should give you a check box with the correct
value defined. so it can be used in the validators. It works server side but client side it fails.
[ValidationProperty("ValidationValue")]
public class ValidifiableCheckBox : CheckBox
{
public string ValidationValue{
get { return (this.checked ? bool.TrueString : string.Empty); }
}
}
it could also be validly defined as: -
[ValidationProperty("Wibble")]
public class CheckBoxWithValue : CheckBox
{
public string Wibble{
get { return (this.checked ? bool.TrueString : string.Empty); }
}
}
If in the ServerValidate you access args.Value you will get the output of Wibble, however this
doesn't change the client side functionality which always just returns "on". regardless of checked
state.
> IMO the problem is that the checkbox input control doesn"t have a value
> property. What is the bool variable you are referring to ?
[quoted text clipped - 78 lines]
>>>>
>>>>Why did microsoft not make the CheckBox control validatable?