|
|
|
start date: Wed, 01 Aug 2007 07:04:11 -0700,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
HockeyFan
|
|
2
Teemu Keiski
|
|
3
Peter Bucher [MVP]
|
|
4
HockeyFan
|
Validator question
I've got a dropdownlist that upon user selection, I have a javascript
function that is run. This function, depending upon which selection
from the dropdown, turns one small section visible and enables its
validator, and turns another similar section off and turns off its
validator. I run this function also on page load, so that it'll run
based on current settings from the database. It works fine, except
that if the user changes the selection, then the validator displays
the error message (because the text box is empty). The thing is, I
set CausesValidation to false on the dropdownlist, so I'm not sure why
this is happening.
Any ideas:
function ddlLoanSystem_Changed()
{
var ddlLoanSystem = document.getElementById('ddlLoanSystem');
var valtxtACCustomerNumber =
document.getElementById('rptBorrower_ctl00_valtxtACCustomerNumber');
var valtxtWCCustomerNumber =
document.getElementById('rptBorrower_ctl00_valtxtWCCustomerNumber');
var spanACCustomerNumber =
document.getElementById('rptBorrower_ctl00_spanACCustomerNumber');
var spanWCCustomerNumber =
document.getElementById('rptBorrower_ctl00_spanWCCustomerNumber');
switch(ddlLoanSystem.options[ddlLoanSystem.selectedIndex].value)
{
case 'ALS':
spanWCCustomerNumber.style.display = 'none';
ValidatorEnable(valtxtWCCustomerNumber, false);
spanACCustomerNumber.style.display = '';
ValidatorEnable(valtxtACCustomerNumber, true);
break;
case 'ACBS':
spanWCCustomerNumber.style.display = '';
ValidatorEnable(valtxtWCCustomerNumber, true);
spanACCustomerNumber.style.display = 'none';
ValidatorEnable(valtxtACCustomerNumber, false);
break;
}
}
Date:Wed, 01 Aug 2007 07:04:11 -0700
Author:
|
Re: Validator question
CausesValidation has impact only on Buttons - in ASP.NET 2.0 controls which
implement IButtonControl interface. See the rendered HTML what's on onchange
attribute of the SELECT element, it should give clue what's going on
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"HockeyFan" wrote in message
news:1185977051.577067.38100@i13g2000prf.googlegroups.com...
> I've got a dropdownlist that upon user selection, I have a javascript
> function that is run. This function, depending upon which selection
> from the dropdown, turns one small section visible and enables its
> validator, and turns another similar section off and turns off its
> validator. I run this function also on page load, so that it'll run
> based on current settings from the database. It works fine, except
> that if the user changes the selection, then the validator displays
> the error message (because the text box is empty). The thing is, I
> set CausesValidation to false on the dropdownlist, so I'm not sure why
> this is happening.
>
> Any ideas:
>
> function ddlLoanSystem_Changed()
> {
> var ddlLoanSystem = document.getElementById('ddlLoanSystem');
> var valtxtACCustomerNumber =
> document.getElementById('rptBorrower_ctl00_valtxtACCustomerNumber');
> var valtxtWCCustomerNumber =
> document.getElementById('rptBorrower_ctl00_valtxtWCCustomerNumber');
> var spanACCustomerNumber =
> document.getElementById('rptBorrower_ctl00_spanACCustomerNumber');
> var spanWCCustomerNumber =
> document.getElementById('rptBorrower_ctl00_spanWCCustomerNumber');
>
> switch(ddlLoanSystem.options[ddlLoanSystem.selectedIndex].value)
> {
> case 'ALS':
> spanWCCustomerNumber.style.display = 'none';
> ValidatorEnable(valtxtWCCustomerNumber, false);
> spanACCustomerNumber.style.display = '';
> ValidatorEnable(valtxtACCustomerNumber, true);
> break;
> case 'ACBS':
> spanWCCustomerNumber.style.display = '';
> ValidatorEnable(valtxtWCCustomerNumber, true);
> spanACCustomerNumber.style.display = 'none';
> ValidatorEnable(valtxtACCustomerNumber, false);
> break;
> }
> }
>
Date:Wed, 1 Aug 2007 17:43:57 +0300
Author:
|
Re: Validator question
Hello les
> function ddlLoanSystem_Changed()
> {
> var ddlLoanSystem = document.getElementById('ddlLoanSystem');
> var valtxtACCustomerNumber =
> document.getElementById('rptBorrower_ctl00_valtxtACCustomerNumber');
> var valtxtWCCustomerNumber =
Use <Control>.ClientID instead of hard coded IDs.
IDs can change! :-)
--
Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
Date:Wed, 1 Aug 2007 18:12:42 +0200
Author:
|
Re: Validator question
>
> Use <Control>.ClientID instead of hard coded IDs.
> IDs can change! :-)
In this case, I can't really pass a control id. The reason is that
this routine, in addition to be run when the dropdown is selected, is
also run at page load. At page load, I have no way of really getting
the control from the repeater, other than I know that it's the control
in the first item of the repeater. If I had a way of accessing the
repeater from javascript, traversing it's contents and gettnig the
control, I would. However, to my knowledge when the page is actually
rendered, there is no repeater, and hence, no way of being able to do
that.
Suggestions are welcome though.
Date:Wed, 01 Aug 2007 10:31:28 -0700
Author:
|
|
|