Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > ControlToValidate

Reply
Thread Tools

ControlToValidate

 
 
Kevin Humphreys
Guest
Posts: n/a
 
      02-14-2007
Hi There,
I am trying to implement the following criteria for the controltovalidate
web control.
If a checkbox is checked and a textbox is empty then accept the validation
as true and process some code if the page is valid
If a checkbox is unchecked and a textbox is empty then treat the validation
as false and not allow to process some more code.

Any ideas?

Thanks,
Kevin.


 
Reply With Quote
 
 
 
 
marss
Guest
Posts: n/a
 
      02-15-2007

Kevin Humphreys wrote:
> Hi There,
> I am trying to implement the following criteria for the controltovalidate
> web control.
> If a checkbox is checked and a textbox is empty then accept the validation
> as true and process some code if the page is valid
> If a checkbox is unchecked and a textbox is empty then treat the validation
> as false and not allow to process some more code.
>
> Any ideas?
>
> Thanks,
> Kevin.


Use CustomValidator.
http://msdn.microsoft.com/library/de...classtopic.asp

 
Reply With Quote
 
 
 
 
Kevin Humphreys
Guest
Posts: n/a
 
      02-15-2007
Hi,
Thanks for this. However the custom validator also validates based on 1
control only.
I am trying to validate based on the criteria of 2 controls.

Any Ideas?

Thanks,
Kevin.

"marss" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> Kevin Humphreys wrote:
>> Hi There,
>> I am trying to implement the following criteria for the controltovalidate
>> web control.
>> If a checkbox is checked and a textbox is empty then accept the
>> validation
>> as true and process some code if the page is valid
>> If a checkbox is unchecked and a textbox is empty then treat the
>> validation
>> as false and not allow to process some more code.
>>
>> Any ideas?
>>
>> Thanks,
>> Kevin.

>
> Use CustomValidator.
> http://msdn.microsoft.com/library/de...classtopic.asp
>



 
Reply With Quote
 
marss
Guest
Posts: n/a
 
      02-16-2007

Kevin Humphreys wrote:
> Hi,
> Thanks for this. However the custom validator also validates based on 1
> control only.
> I am trying to validate based on the criteria of 2 controls.
>
> Any Ideas?
>
> Thanks,
> Kevin.


Hi,
The CustomValidator implements custom validation irregardless of the
control's number.
Example.
..ascx
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Error!"
OnServerValidate="CustomValidator1_ServerValidate" ></
asp:CustomValidator>

..cs
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
if (CheckBox1.Checked)
args.IsValid = TextBox1.Text.Length == 0;
else
args.IsValid = TextBox1.Text.Length > 0;
}

Regards,
Mykola

 
Reply With Quote
 
Kevin Humphreys
Guest
Posts: n/a
 
      02-19-2007
Got it. Thanks a lot.

"marss" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> Kevin Humphreys wrote:
>> Hi,
>> Thanks for this. However the custom validator also validates based on 1
>> control only.
>> I am trying to validate based on the criteria of 2 controls.
>>
>> Any Ideas?
>>
>> Thanks,
>> Kevin.

>
> Hi,
> The CustomValidator implements custom validation irregardless of the
> control's number.
> Example.
> .ascx
> <asp:CheckBox ID="CheckBox1" runat="server" />
> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
> <asp:CustomValidator ID="CustomValidator1" runat="server"
> ErrorMessage="Error!"
> OnServerValidate="CustomValidator1_ServerValidate" ></
> asp:CustomValidator>
>
> .cs
> protected void CustomValidator1_ServerValidate(object source,
> ServerValidateEventArgs args)
> {
> if (CheckBox1.Checked)
> args.IsValid = TextBox1.Text.Length == 0;
> else
> args.IsValid = TextBox1.Text.Length > 0;
> }
>
> Regards,
> Mykola
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy access to the control specified in a validator's ControlToValidate property Nathan Sokalski ASP .Net 0 03-08-2010 08:23 PM
Accessing the ControlToValidate control in a Validator Nathan Sokalski ASP .Net 1 05-20-2008 10:49 PM
document.getElementById(sender.controltovalidate) attributes DaveyP ASP .Net 1 04-18-2008 12:21 PM
Custom Control needs ControlToValidate Steven Nagy ASP .Net 4 05-08-2007 03:56 AM
custom validator and ControlToValidate in a composite control... Donal McWeeney ASP .Net Building Controls 1 09-29-2004 08:45 AM



Advertisments