473,658 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I tie a validator to two controls at once?

Hello,

I have two dropdown controls on a form, representing a month/year
combination. The date entered must be in the future, so I wrote a custom
validator to check this. Trouble is, the validator is only tied to one
control (currently the month dropdown), which means that the validation
isn't fired when the other control's value changes.

Is there a way of getting the client-side validation code to fire when
either one of two controls is changed? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 20 '05 #1
11 1472
These validation controls opened up a whole new world for me:

http://www.peterblum.com/VAM/Home.aspx

You can fulfill your requirement, plus more.

--
Jay Douglas
http://www.jaydouglas.com
"Alan Silver" <al*********@no spam.thanx> wrote in message
news:jw******** ******@nospamth ankyou.spam...
Hello,

I have two dropdown controls on a form, representing a month/year
combination. The date entered must be in the future, so I wrote a custom
validator to check this. Trouble is, the validator is only tied to one
control (currently the month dropdown), which means that the validation
isn't fired when the other control's value changes.

Is there a way of getting the client-side validation code to fire when
either one of two controls is changed? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 20 '05 #2
>These validation controls opened up a whole new world for me:

http://www.peterblum.com/VAM/Home.aspx

You can fulfill your requirement, plus more.


Thanks, they look very good.

I assume from your answer that what I want to do can't easily be done in
ASP.NET? I wondered if the changes in 2.0 had brought any improvements
to the validation controls.

Thanks for the reply

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 20 '05 #3
From what I've noticed, the validation controls in 2.0 have not made great
gains in the way of functionality. There are some new things like setting
focus on error and a few other items.

--
Jay Douglas
http://www.jaydouglas.com
"Alan Silver" <al*********@no spam.thanx> wrote in message
news:iw******** ******@nospamth ankyou.spam...
These validation controls opened up a whole new world for me:

http://www.peterblum.com/VAM/Home.aspx

You can fulfill your requirement, plus more.


Thanks, they look very good.

I assume from your answer that what I want to do can't easily be done in
ASP.NET? I wondered if the changes in 2.0 had brought any improvements to
the validation controls.

Thanks for the reply

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 20 '05 #4
>From what I've noticed, the validation controls in 2.0 have not made great
gains in the way of functionality. There are some new things like setting
focus on error and a few other items.


There was talk of validation groups, but I haven't had time to look in
the docs and see if that made it in.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 20 '05 #5
You can do anything you want. You're a programmer!

This is pretty straightforward . I just add another attribute to the
validator tag, like secondControl=" txtDate2". It will render as an
attribute of the DIV used for the validator and you'll get a reference
to that DIV (or is it a Span?) in the custom validation function. Just
grab the attribute, getElementByID( ), and you're good to go.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/

Nov 20 '05 #6
Yes, there are validation groups... Big improvement =)

--
Jay Douglas
http://www.jaydouglas.com
"Alan Silver" <al*********@no spam.thanx> wrote in message
news:gh******** ******@nospamth ankyou.spam...
From what I've noticed, the validation controls in 2.0 have not made
great
gains in the way of functionality. There are some new things like setting
focus on error and a few other items.


There was talk of validation groups, but I haven't had time to look in the
docs and see if that made it in.

--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 20 '05 #7
>You can do anything you want. You're a programmer!

Oh yeah, I forgot!!
This is pretty straightforward . I just add another attribute to the
validator tag, like secondControl=" txtDate2". It will render as an
attribute of the DIV used for the validator and you'll get a reference
to that DIV (or is it a Span?) in the custom validation function. Just
grab the attribute, getElementByID( ), and you're good to go.


OK, but the one bit I don't get is how I get the validation routine to
be fired by the second control. You'll have to excuse me, but my
knowledge of the client-side bits is pretty sketchy at the moment.

If I read your words right, adding the attribute merely gives me a
reference to the second control. I can already do that from plain old
Javascript, that's how I do the validation now. What I need is to get
the second control to fire the validation code.

Maybe I'm missing something here, but I'm not sure how your suggestion
helps. Thanks for the reply, any further ideas would be welcome.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 20 '05 #8
In practice, I've always found that these two-control validators really
key off a single control. For a date range, for example, you're not
going to want to stick up a red warning message before they even get
around to filling in the second box.

But if you really want to fire for each control, it's simple enough.
View source, copy the onchange="..." out of the control that's hooked
up through the validator. Paste it into the unhooked input control,
tweak it to fit your needs, and you're good to go.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/

Nov 20 '05 #9
>In practice, I've always found that these two-control validators really key
off a single control. For a date range, for example, you're not going to
want to stick up a red warning message before they even get around to
filling in the second box.
No, I see your point. But there are conditions in which this approach is
useful.
But if you really want to fire for each control, it's simple enough. View
source, copy the onchange="..." out of the control that's hooked up
through the validator. Paste it into the unhooked input control, tweak it
to fit your needs, and you're good to go.


Except that the code doesn't seem to hook up to the onchange event.
Truth is, I can't actually see how the client-side validators fire at
all from looking at the HTML produced.

For example, here is the code for the <select> for this control...

<select name="drpFromYe ar" id="drpFromYear ">
<option value="2000">20 00</option>
<option value="2001">20 01</option>
<option value="2002">20 02</option>
<option value="2003">20 03</option>
<option value="2004">20 04</option>
<option value="2005">20 05</option>

</select>

Nothing there to tell the browser to fire the event when the user
changes the control. I can't see anything relevant elsewhere in the file
either.

Any idea? Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2227
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These controls and validators are then added to a table for display to the user. This code did seem to work originally, but now does not amd I am stumped as to why. There have been some code changes, but not to the methods below and I have pretty much...
2
3904
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I did some work on was having the control implement the IValidator interface and basically recreating...
2
3156
by: Dune | last post by:
Hi there, If a control is disabled (enabled = false), will the validator controls associated with it automatically know not to carry out validation? I have a page with a bunch of controls and depending on what is passed in through the querystring, I disable some of those controls in my code-behind. However, my validator controls still seem to be trying to validate the disabled controls. Cheers :)
9
5148
by: Alex Shirley | last post by:
Hi there I’m simply trying to check for a blank or empty value in a textbox on my webform. In this instance I do not want to use a requiredfieldvalidator, I want to use a customvalidator (as I have other code within the customvalidator which works). This won’t work (within servervalidate): If txtBox.Text.ToString = "" Then raise exception…..
3
1668
by: Angelos Karantzalis | last post by:
Hi guys, I've a small problem with validators. I'm building a single .aspx file that handles all my form posts. I need to be using ASP.NET validators ( or subclasses thereof ), so what i do to overcome the fact that i don't really know what sort of input controls I'm working with is this: 1) I've got the form description in xml, so I know all the fields I'm
3
1222
by: danny.rendle | last post by:
I am attempting to create a web site using ASP.NET v1.1 to comply with the W3C's WAI Triple-A standard. To this end I need ASP.NET to emit valid HTML 4.01 Transitional (once confident with ASP.NET and HTML 4.01 I plan to move onto XHTML). I have found several articles suggesting the use of Response Filters to amend the HTML on route to the client which are very usefull for adding a container for the ViewState and removing the Form's...
1
1723
by: Sam | last post by:
Hi all, Why can't i create a validatorControl as a child of the control to validate? It doesn't give any errors, but it just won't work (it's not validating). The reason why i want this is that i'm creating a repository of WebControls extended/inherited with my own code for repetative use. For example, i have a: Class CreationDate inherits TextBox I offcourse want a validator to check is really a date was entered into the textbox.
1
1207
by: Tarun Mistry | last post by:
Hi there everyone, I have a page containing dynamic user controls. The main page contains a custom validator that checks the dynamic user controls, this works fine. However, I only want the custom validator to fire when the main submit button on the page is executed, not the ones within the user control. Is this possible at all? Right now the custom validator executes whenever any submit button is pressed which is not allowing the user...
2
4533
by: Mike Collins | last post by:
I have a form where I create dynamic controls at runtime. With this, I am adding a dynamic required field validator to each control as needed, but the validators are not firing when I click submit. The submit button was placed at design time and its causesvalidation property is set to true. Can someone tell me if something is missing from my code? Thank you. 1. Code to add dynamic control works fine and I get the Id of the textbox...
0
8330
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
8850
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...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8626
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
7355
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...
0
5649
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
2749
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
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.