I've not been able to get a Check box to client side validated on postback. with my changes I can
get it to work on the serverside ok but not on the client.
I have created a new control as below:-
[ValidationProperty("ValidationValue")]
public class ValidifiableCheckBox: CheckBox
{
public string ValidationValue{
get { return (this.checked ? bool.TrueString : string.Empty); }
}
}
this gives me a CheckBox that the Validators will except (rather than throwing an exception about
not being able to validate them), If I use it with a RequiredFieldValidator, the Serverside events
valdiation works however it doesn't seem to trap it on the client, my page code is bellow: -
<myControls:ValidifiableCheckBox ID="cbAgree" runat="server"/>
<asp:RequiredFiledValidator ID="rfvAgree" runat="server" ControlToValidate="cbAgree"
ErrorMessage="Oh Dear" Text="*"/>
<asp:ValidationSummary ID="vsAgree" runat="server" ShowMessageBox="true" ShowSummary="false"/>
Any ideas?
Why did microsoft not make the CheckBox control validatable? 7 2422
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
priority (my understainding is that you want to display a checkbox that is
necessarily checked).
Also I would try a compareValidator rather than a requiredfield validator
(you want the value to be true, "on" or whatever else is used for a checked
box, if the box is unchecked it doesn't mean IMO that a value hasn't been
provided but that the value provided by the user is just "false").
Finally if you have to create your own validator, see for example http://aspnet.4guysfromrolla.com/articles/073102-1.aspx. Server validation
is fine but AFAIK you have to provide client side validation code if you
want to validate this client side (server side code runs server side and
can't be run or won't be transformed automatically for the client side
handling).
--
Patrice
"mc" <mc@community.nospama écrit dans le message de news:
47********@mail.hmgcc.gov.uk...
I've not been able to get a Check box to client side validated on
postback. with my changes I can get it to work on the serverside ok but
not on the client.
I have created a new control as below:-
[ValidationProperty("ValidationValue")]
public class ValidifiableCheckBox: CheckBox
{
public string ValidationValue{
get { return (this.checked ? bool.TrueString : string.Empty); }
}
}
this gives me a CheckBox that the Validators will except (rather than
throwing an exception about not being able to validate them), If I use it
with a RequiredFieldValidator, the Serverside events valdiation works
however it doesn't seem to trap it on the client, my page code is
bellow: -
<myControls:ValidifiableCheckBox ID="cbAgree" runat="server"/>
<asp:RequiredFiledValidator ID="rfvAgree" runat="server"
ControlToValidate="cbAgree" ErrorMessage="Oh Dear" Text="*"/>
<asp:ValidationSummary ID="vsAgree" runat="server" ShowMessageBox="true"
ShowSummary="false"/>
Any ideas?
Why did microsoft not make the CheckBox control validatable?
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.GetTyp e(), "ClientValidateVCB", csValidFunc, true);
}
protected void cvAgree_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = (args.Value == bool.TrueString);
}
Patrice wrote:
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
priority (my understainding is that you want to display a checkbox that is
necessarily checked).
Also I would try a compareValidator rather than a requiredfield validator
(you want the value to be true, "on" or whatever else is used for a checked
box, if the box is unchecked it doesn't mean IMO that a value hasn't been
provided but that the value provided by the user is just "false").
Finally if you have to create your own validator, see for example http://aspnet.4guysfromrolla.com/articles/073102-1.aspx. Server validation
is fine but AFAIK you have to provide client side validation code if you
want to validate this client side (server side code runs server side and
can't be run or won't be transformed automatically for the client side
handling).
--
Patrice
"mc" <mc@community.nospama écrit dans le message de news:
47********@mail.hmgcc.gov.uk...
>>I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client.
I have created a new control as below:-
[ValidationProperty("ValidationValue")] public class ValidifiableCheckBox: CheckBox { public string ValidationValue{ get { return (this.checked ? bool.TrueString : string.Empty); } } }
this gives me a CheckBox that the Validators will except (rather than throwing an exception about not being able to validate them), If I use it with a RequiredFieldValidator, the Serverside events valdiation works however it doesn't seem to trap it on the client, my page code is bellow: -
<myControls:ValidifiableCheckBox ID="cbAgree" runat="server"/> <asp:RequiredFiledValidator ID="rfvAgree" runat="server" ControlToValidate="cbAgree" ErrorMessage="Oh Dear" Text="*"/> <asp:ValidationSummary ID="vsAgree" runat="server" ShowMessageBox="true" ShowSummary="false"/>
Any ideas?
Why did microsoft not make the CheckBox control validatable?
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...18c.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> Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Re: Validating CheckBoxes on the ClientSide
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.GetTy pe(),
"ClientValidateVCB", csValidFunc, true);
>}
protected void cvAgree_ServerValidate(object source,
ServerValidateEventArgs args)
>{
args.IsValid = (args.Value == bool.TrueString); }
Patrice wrote:
>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
>priority (my understainding is that you want to display a checkbox that
is
>necessarily checked).
Also I would try a compareValidator rather than a requiredfield
validator
>(you want the value to be true, "on" or whatever else is used for a
checked
>box, if the box is unchecked it doesn't mean IMO that a value hasn't
been
>provided but that the value provided by the user is just "false").
Finally if you have to create your own validator, see for example http://aspnet.4guysfromrolla.com/articles/073102-1.aspx. Server
validation
>is fine but AFAIK you have to provide client side validation code if you want to validate this client side (server side code runs server side and can't be run or won't be transformed automatically for the client side handling).
-- Patrice
"mc" <mc@community.nospama écrit dans le message de news: 47********@mail.hmgcc.gov.uk...
>>>I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client.
I have created a new control as below:-
[ValidationProperty("ValidationValue")] public class ValidifiableCheckBox: CheckBox { public string ValidationValue{ get { return (this.checked ? bool.TrueString : string.Empty); } } }
this gives me a CheckBox that the Validators will except (rather than throwing an exception about not being able to validate them), If I use
it
>>>with a RequiredFieldValidator, the Serverside events valdiation works however it doesn't seem to trap it on the client, my page code is bellow: -
<myControls:ValidifiableCheckBox ID="cbAgree" runat="server"/> <asp:RequiredFiledValidator ID="rfvAgree" runat="server" ControlToValidate="cbAgree" ErrorMessage="Oh Dear" Text="*"/> <asp:ValidationSummary ID="vsAgree" runat="server" ShowMessageBox="true" ShowSummary="false"/>
Any ideas?
Why did microsoft not make the CheckBox control validatable?
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
"mc" <mc@community.nospama écrit dans le message de news:
47********@mail.hmgcc.gov.uk...
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.GetTyp e(),
"ClientValidateVCB", csValidFunc, true);
}
protected void cvAgree_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = (args.Value == bool.TrueString);
}
Patrice wrote:
>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 priority (my understainding is that you want to display a checkbox that is necessarily checked).
Also I would try a compareValidator rather than a requiredfield validator (you want the value to be true, "on" or whatever else is used for a checked box, if the box is unchecked it doesn't mean IMO that a value hasn't been provided but that the value provided by the user is just "false").
Finally if you have to create your own validator, see for example http://aspnet.4guysfromrolla.com/articles/073102-1.aspx. Server validation is fine but AFAIK you have to provide client side validation code if you want to validate this client side (server side code runs server side and can't be run or won't be transformed automatically for the client side handling).
-- Patrice
"mc" <mc@community.nospama écrit dans le message de news: 47********@mail.hmgcc.gov.uk...
>>>I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client.
I have created a new control as below:-
[ValidationProperty("ValidationValue")] public class ValidifiableCheckBox: CheckBox { public string ValidationValue{ get { return (this.checked ? bool.TrueString : string.Empty); } } }
this gives me a CheckBox that the Validators will except (rather than throwing an exception about not being able to validate them), If I use it with a RequiredFieldValidator, the Serverside events valdiation works however it doesn't seem to trap it on the client, my page code is bellow: -
<myControls:ValidifiableCheckBox ID="cbAgree" runat="server"/> <asp:RequiredFiledValidator ID="rfvAgree" runat="server" ControlToValidate="cbAgree" ErrorMessage="Oh Dear" Text="*"/> <asp:ValidationSummary ID="vsAgree" runat="server" ShowMessageBox="true" ShowSummary="false"/>
Any ideas?
Why did microsoft not make the CheckBox control validatable?
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
Steven Cheng[MSFT] wrote:
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...18c.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> Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Re: Validating CheckBoxes on the ClientSide
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.GetT ype(),
"ClientValidateVCB", csValidFunc, true);
>>}
protected void cvAgree_ServerValidate(object source,
ServerValidateEventArgs args)
>>{ args.IsValid = (args.Value == bool.TrueString); }
Patrice wrote:
>>>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
>>>priority (my understainding is that you want to display a checkbox that
is
>>>necessarily checked).
Also I would try a compareValidator rather than a requiredfield
validator
>>>(you want the value to be true, "on" or whatever else is used for a
checked
>>>box, if the box is unchecked it doesn't mean IMO that a value hasn't
been
>>>provided but that the value provided by the user is just "false").
Finally if you have to create your own validator, see for example http://aspnet.4guysfromrolla.com/articles/073102-1.aspx. Server
validation
>>>is fine but AFAIK you have to provide client side validation code if you want to validate this client side (server side code runs server side and can't be run or won't be transformed automatically for the client side handling).
-- Patrice
"mc" <mc@community.nospama écrit dans le message de news: 47********@mail.hmgcc.gov.uk...
I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client.
I have created a new control as below:-
[ValidationProperty("ValidationValue")] public class ValidifiableCheckBox: CheckBox { public string ValidationValue{ get { return (this.checked ? bool.TrueString : string.Empty); } } }
this gives me a CheckBox that the Validators will except (rather than throwing an exception about not being able to validate them), If I use
it
>>>>with a RequiredFieldValidator, the Serverside events valdiation works however it doesn't seem to trap it on the client, my page code is bellow: -
<myControls:ValidifiableCheckBox ID="cbAgree" runat="server"/> <asp:RequiredFiledValidator ID="rfvAgree" runat="server" ControlToValidate="cbAgree" ErrorMessage="Oh Dear" Text="*"/> <asp:ValidationSummary ID="vsAgree" runat="server" ShowMessageBox="true" ShowSummary="false"/>
Any ideas?
Why did microsoft not make the CheckBox control validatable?
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/lib...ng(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.
Patrice wrote:
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
"mc" <mc@community.nospama écrit dans le message de news:
47********@mail.hmgcc.gov.uk...
>>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.GetT ype(), "ClientValidateVCB", csValidFunc, true); }
protected void cvAgree_ServerValidate(object source, ServerValidateEventArgs args) { args.IsValid = (args.Value == bool.TrueString); }
Patrice wrote:
>>>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 priority (my understainding is that you want to display a checkbox that is necessarily checked).
Also I would try a compareValidator rather than a requiredfield validator (you want the value to be true, "on" or whatever else is used for a checked box, if the box is unchecked it doesn't mean IMO that a value hasn't been provided but that the value provided by the user is just "false").
Finally if you have to create your own validator, see for example http://aspnet.4guysfromrolla.com/articles/073102-1.aspx. Server validation is fine but AFAIK you have to provide client side validation code if you want to validate this client side (server side code runs server side and can't be run or won't be transformed automatically for the client side handling).
-- Patrice
"mc" <mc@community.nospama écrit dans le message de news: 47********@mail.hmgcc.gov.uk...
I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client.
I have created a new control as below:-
[ValidationProperty("ValidationValue")] public class ValidifiableCheckBox: CheckBox { public string ValidationValue{ get { return (this.checked ? bool.TrueString : string.Empty); } } }
this gives me a CheckBox that the Validators will except (rather than throwing an exception about not being able to validate them), If I use it with a RequiredFieldValidator, the Serverside events valdiation works however it doesn't seem to trap it on the client, my page code is bellow: -
<myControls:ValidifiableCheckBox ID="cbAgree" runat="server"/> <asp:RequiredFiledValidator ID="rfvAgree" runat="server" ControlToValidate="cbAgree" ErrorMessage="Oh Dear" Text="*"/> <asp:ValidationSummary ID="vsAgree" runat="server" ShowMessageBox="true" ShowSummary="false"/>
Any ideas?
Why did microsoft not make the CheckBox control validatable?
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/feedbac...spx?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> Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Re: Validating CheckBoxes on the ClientSide
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
Steven Cheng[MSFT] wrote:
>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...18c.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.
>>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anna |
last post by:
Hi all.
I have a form with a few text boxes which need to be validated client-side.
The validation is: check that every single text box has a unique string value.
I.e., I need to check that...
|
by: Miguel Orrego |
last post by:
Hi,
I have a form that is created dynamically from a recordset, this creates a
line for each record together with 2 checkboxes, Yes & No so the source
output would be something like this:
...
|
by: sman |
last post by:
Hi, I recently read this article on About.com on how to create
required fields for a form:
http://javascript.about.com/library/scripts/blformvalidate.htm
Everything works great except that there...
|
by: Stephen |
last post by:
Could someone please help me with some validation. I have to write code which
checks to see whether a dropdown list is populated with a value or a checkbox
is checked. I want the code to run on the...
|
by: Jaime Stuardo |
last post by:
Hi all...
I'm trying to use a custom validator for a group of checkboxes in order to
validate that at least 1 checkbox is checked before submitting the form.
I placed 2 checkbox controls in...
|
by: Blinky |
last post by:
Hi all,
I have a dynamically generated page that can have 1 or more radio buttons. I
am using javascript with onsubmit in the form statement to make sure a radio
button is selected before...
|
by: James Jones |
last post by:
I've never used checkboxes in ASP, well nows the time i do it.
Im creating a login script, and want the user to be able to click on "remember me"
it keep them logged in.
how would i get...
|
by: forbes |
last post by:
Hi,
I have a form that contains multiple groups of checkboxes that act
like radio buttons (at the clients insistance).
There is one text field that is required and 28 checkbox groups.
Here an...
|
by: Ned Balzer |
last post by:
Hi,
Can anyone point me in the direction of a solution for validating
multiple checkboxes in an asp.net 2.0 page?
1) This is not a checkboxlist, it is a number of separate checkboxes
2) I do...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |