Validator question

H

HockeyFan

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

Teemu Keiski

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
 
P

Peter Bucher [MVP]

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! :)
 
H

HockeyFan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top