473,394 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1451
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*********@nospam.thanx> wrote in message
news:jw**************@nospamthankyou.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*********@nospam.thanx> wrote in message
news:iw**************@nospamthankyou.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*********@nospam.thanx> wrote in message
news:gh**************@nospamthankyou.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="drpFromYear" id="drpFromYear">
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</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
Nothing to stop you firing it manually. It's just javascript after
all.

<select name="drpFromYear" id="drpFromYear"
onchange="runYourValidator()">
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
</select>

<script>

function runYourValidator()
{
// validate by hand and flip the validator divs on and off as
needed.
}

</script>
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 #11
>Nothing to stop you firing it manually. It's just javascript after
all.
OK, that's certainly a help, but it would be nice if there was a way to
fire the proper validation code. I presume that there must be an
onchange event buried deep in the validation code that the framework
provides. Why can't I just get that to fire? Or put a better way, why
can't I call something in the onchange event of my dropdown that will
fire the validation code with the appropriate objects passed as
parameters?

One big advantage of the built-in way of doing it (as opposed to what
you showed) is that you get the chance to set IsValid, which
automatically sets the display of the validation summary, sets the error
message next to the control (using the ErrorMessage property of the
individual validator), pops up the message box and cancels the form
submit. That's a lot of work done for you. Sure I could do this all
myself, but it's a lot of work and is not guaranteed to work in the
future. MS could easily change the way the validation works, and my page
would stop working.

Thanks for the reply. Any further ideas?
<select name="drpFromYear" id="drpFromYear"
onchange="runYourValidator()">
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
</select>

<script>

function runYourValidator()
{
// validate by hand and flip the validator divs on and off as
needed.
}

</script>
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/


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

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

Similar topics

0
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...
2
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...
2
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...
9
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...
3
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...
3
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...
1
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...
1
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...
2
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....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.