Validators - How to enable/disable validation of Control A on the client side based on the input from Control B

Hello,

I've come across the problem when I wanted to use client side validation (no matter of which type) depending on the input from a different control.

The scenario is: I have two textboxes A and B. A does not need to be validated (no validator associated with A). The textbox B has to be validated if and only if the A has any value.

I know this is trivial with custom validator in the server side mode... But unfortunately I want it to run the validation on the client side. And I also know that I can write a javascript function for the ClientValidationFunction and hardcode client id of the parent control - that's not a problem, but that is not the cleanest solution...

I have already started building my custom validator control, but maybe the solution is much simpler than I think.

Do you have any idea?


Robert Kafarski,

Aure Entuluva!
- Day shall come again!
0
fafar
7/8/2007 3:23:01 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

4 Replies
1264 Views

Similar Articles

[PageSpeed] 4

Hey..In order to execute the input validation in a controlled manner, try defining different validation group for different set of validators and the buttons accordingly. For example, say Textbox A has validation group "A" and TextBoxB has validation group "B" and your button "Button1" has validation group "A" defined. Now, the button click will validate only those validation with validation group of "A"...got it?


Ziyad Mohammad
http://dotnetsoldier.blogspot.com

http://znetcontrols.blogspot.com/
0
ziyad
7/8/2007 4:01:42 AM

Hi Ziyad,

To be more precise: I need the validation to be triggered by one button.

I know how validation groups work, but I do not see the solution using them in my case, because there is only one validation group here.

The TextBox A does not need to be validated, but only the TextBox B when the TextBox A has any value.

The tricky thing is when I click the button, my validation should only be done when I have a value in the "parent" control and it has to be done on the client side. As I mentioned before, I can do it using custom validator and javascript, but I was looking for something simpler and more clean. I have no idea if this can be done in the vanilla version of the .net 2.0 framework...


Robert Kafarski,

Aure Entuluva!
- Day shall come again!
0
fafar
7/8/2007 4:17:18 AM

Okay,

I am going to describe what I would like to do in more understable way:

In my case I have a choice of creating one or two database records in two separate tables. One record would consist of contact info and the optional second one - user account related data.

I would like to create a user account only if a username is provided in the textbox A. And if the username in the textbox A is not an empty string then I would like to make password field - TextBox B required.

If they are both empty I do not want to create a user account.

I would like this to be evaluated on the client side...

I appreciate any suggestion!


Robert Kafarski,

Aure Entuluva!
- Day shall come again!
0
fafar
7/8/2007 4:46:21 AM

Then my answer is you have to disable the validator from javascript. There is a better way to disable the  validator in javascript using the following function and the flip side is it will work only in IE

ValidatorEnable(<Validator Name>, <boolean - true or false>);

Hence, in your javascript, you can check the text length of username and then enable /disable the validators accordingly...


Ziyad Mohammad
http://dotnetsoldier.blogspot.com

http://znetcontrols.blogspot.com/
0
ziyad
7/8/2007 5:39:39 AM
Reply:

Similar Artilces:

Controlling the controls a validator validates
Hello, I want to control which controls appear for a validator when they go to controltovalidate dropdown in property grid.  Is the solution to create a designer for the control?  How do you regulate that?  I can't override the ControlToValidate property... Thanks.Brian"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4). Well ur logic is true, thats the way, what u need to do is not override the property (cant), create another property, that implemen...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

validation, is it better to have client side or use server side validator controls
 Hi All. I want to do validation on text boxes etc. Is it better to do client side validation or just use the server side validation controls?   Hi!  If for server side controls you mean RequiredFieldValidator, CompareValidator, RegularExpressionValidator, etc.. i can tell you that they use client and server validation. For instance if you use a RequiredFieldValidator, on the client will be a validation, but on the server this condition will be evaluated again. Probably one of the objetives of this is deal with client with javascript disabled. Of course I ...

Client Side Validation For Custom Controls / Validators
Hi there people, I'm creating my own set of self validating text boxes. They all inherit from a base text box which simply contains a required field validator, they then usuallly implement another validator to check they contain number, currencies, dates or whatever. The problem i'm having is with the DateTextBox, I have created my own Date Validator which inherits from the BaseValidator class which the DateTextBox uses. My problem is that no validation is taking place on the client side. I've included the code for all related parts, if you need anymore info then please just let me k...

custom validation control client side validation did not work
<head runat="server"><script language=JavaScript >  function vrNameLenght( sender, args){  if (args.Value.Length > 15) args.IsValid = false; elseargs.IsValid = true;   }  </script> </head> <form id="form1" runat="server">                  <asp:ValidationSummary ID="ValidationSummary1" runat="server" />        <table align =center  width=750  &...

Part 2
Thanks to the help of this forum I solved my previous problem of adding client side validation to my date validator class. Though I found an interesting feature with it. To give some background I'm creating selfvalidating text boxes, one for date's, another for currency etc... Each textbox class inherits from a base textbox class which is simply a textbox with a RequiredFieldValidator bolted on. This way I can allow blanks (or not). Now with most of my textboxes I simply inherit from my base textbox class and then add another validator - eg in my number textbox I add a RegularExpre...

Enable/Disable validation control client side
Hello - I was wondering if it possible to disable or enable a validation control through javascript alone. Basically, I have a check box. If the user ticks it, I then require them to fill in a text box. So, ideally, I'd have a requiredFieldValidator for the test box that would only be enabled when the user clicks the text box. Thing is - I'd rather do that without having to post back to the server to disable or enable the validation control.. Any ideas?? Thanks.http://www.developdesign.co.uk/ To disable or enable server validation control in ASP.NET using JavaScript:   Use the f...

Creating a User Control validator that validates a control on the page, rather than inside the control.
I'm trying to create a custom user control that is nothing more than a RangeValidator that validates other controls that lie on the page rather than inside the control itself... is this possible, is there a way to "bubble" it up. Thanks, G My answer to your other question regarding the CompareValidator applies here. If the custom control is in the same naming container AND does not implement INamingContainer, you can create a property that lets the user assign the control to validate. Internally assign the Validator.ControlToValidate property to the value of that property.-...

validation controls
Hi all,I have a web form with a few controls and reqdfield, compare & regex validation controls. On all validation controls i have enabled the client script property. Yet when I submit the form it does a postback to do the validation. Any ideas? I am running vs2005 beta 2.TIA! Hello.how do these validators perform the validation of the other controlos? whar browser are you using?-- Regards,Luis Abreuemail: labreu_at_gmail.comEN blog:http://msmvps.com/blogs/luisabreu Well they are regular requiredfield, regex & compare validators. Browser is latest version of Firefox. I had to use...

Validation control not doing server side validation?
I think the subject covers what I'm asking.  I want to run some checks on the data that was entered after the page was submitted, but I don't know how to handle it if there's a problem the user has to go back and fix.  So I thought I'd try to work around the validation control to see how .NET handles it.  I have a text field that is required.  When the submit button is clicked, I assume some client side validation is run.  I get the validation message I want and the form won't submit.   But then I made a change in the on click event of the submit butto...

Validation of a control based on input of another control using requiredfieldvalidators
Hi I have a form that has two checkboxes and 6 textboxes. If the first checkbox is checked then I have to validate the first 3 textboxes. If the 2nd checkbox is checked then the other 3. I want to perform this using required field validators.  Can anyone give me an idea on how I can do this?  Thanks in Advance Regards Harihar Hi, If you want to do this in the normal and easy flow then on the click of the check box you have to post back the page and disable the non required field validators. But I think you should go for some javascript so that you will not be required to ...

How to display all of my validation controls in my Validation summary control?
I have a  validation summary control I am using on a web form to validate various controls on a web form. For one of the controls  which is a text box control, I have a custom validation control. When someone presses the save button, all of the controls are validated. If any errors occur, then the error message is displayed in the validation summary area above all of the controls. This is what I want. The problem though is that I also get an error message next to my text box which was assigned the custom validator control. The problem here is that the error message i...

Validation Control question
Hello.  I have a form with several validation controls checking input boxes.  This form also has a DDL (dropdownlist).  This form also has a formview control in insert mode - this formview control has the validation controls.  The formview visibility is set to false. When a user selects an item from the DDL (which causes a postback) I set the visibilty of the formview to true.  At this point the validation controls are showing errors in th evalidation summary even though the user has not attempted to do any inputs. Where or how can I control when the validation ...

Validation controls are triggereing other forms validation controls?
Can someone please look at this an explain whats going on. When you click on subscribe it triggers my registration form validation controls. I'not sure what "subscribe" is supposed to do, but if you dont want it to cause validation, set the CausesValidation property to false.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ Make sure the feild is an email address Hey coolkidsonly, your initial posting didn't show us anything to look at. We are just guessing here without the specifics. However, m...

Web resources about - Validators - How to enable/disable validation of Control A on the client side based on the input from Control B - asp.net.custom-server-controls

CSE HTML Validator for Windows (Official Site) - Powerful HTML Validator, XHTML Validator, CSS Validator ...
CSE HTML Validator is a powerful and easy to use offline HTML, XHTML, CSS, JavaScript, and PHP syntax checker, HTML validator, XHTML validator, ...

DNSSEC/TLSA Validator
DNSSEC/TLSA Validator is a web browser add-on which allows you to check the existence and validity of DNS Security Extensions (DNSSEC) records ...

Feed Validator for Atom and RSS
F E E D Validator for Atom and RSS and KML Jump to navigation RSS Profile Support Added ( more ) Home · About · News · Docs · Terms Copyright ...

Credit Card Validator on the App Store on iTunes
Get Credit Card Validator on the App Store. See screenshots and ratings, and read customer reviews.

Not fare: new myki card validators lack account balance information
New myki card validators will not tell passengers what their fare is, nor their account balance, leaving unable to monitor their myki use as ...

Mozilla launches new JavaScript-based Add-ons Validator for developers
... that the validation tool provided by Mozilla is unreliable and difficult to use. Today the company announces that the old Python-based validator ...

Business Insider Built An Awesome Analytics Validator And You Can Use It
At a fast-growing media company like Business Insider, keeping accurate analytics is absolutely essential. Editors rely on our analytics dashboard ...

Jon Voight, Validator of Right-Wing Frenzy
Jon Voight was once known for his acting chops and, later, for fathering Angelina Jolie. These days? Well, he's known for his rabid right-wing ...

chocolatey/package-validator · GitHub
package-validator - Windows service to validate packages conform to pacakge standards

Bing Webmaster Tools Adds Markup Validator
The Bing Webmaster Blog announced they have added a new feature to the crawl section named Markup Validator. To access this new feature, login ...

Resources last updated: 1/15/2016 5:46:42 AM