Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Validator question (http://www.velocityreviews.com/forums/t526211-validator-question.html)

HockeyFan 08-01-2007 02:04 PM

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_valtxtA CCustomerNumber');
var valtxtWCCustomerNumber =
document.getElementById('rptBorrower_ctl00_valtxtW CCustomerNumber');
var spanACCustomerNumber =
document.getElementById('rptBorrower_ctl00_spanACC ustomerNumber');
var spanWCCustomerNumber =
document.getElementById('rptBorrower_ctl00_spanWCC ustomerNumber');

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;
}
}


Teemu Keiski 08-01-2007 02:43 PM

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" <les.stockton@gmail.com> wrote in message
news:1185977051.577067.38100@i13g2000prf.googlegro ups.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_valtxtA CCustomerNumber');
> var valtxtWCCustomerNumber =
> document.getElementById('rptBorrower_ctl00_valtxtW CCustomerNumber');
> var spanACCustomerNumber =
> document.getElementById('rptBorrower_ctl00_spanACC ustomerNumber');
> var spanWCCustomerNumber =
> document.getElementById('rptBorrower_ctl00_spanWCC ustomerNumber');
>
> 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;
> }
> }
>




Peter Bucher [MVP] 08-01-2007 04:12 PM

Re: Validator question
 
Hello les

> function ddlLoanSystem_Changed()
> {
> var ddlLoanSystem = document.getElementById('ddlLoanSystem');
> var valtxtACCustomerNumber =
> document.getElementById('rptBorrower_ctl00_valtxtA CCustomerNumber');
> 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

HockeyFan 08-01-2007 05:31 PM

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.



All times are GMT. The time now is 02:00 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.