У меня есть addressControl , который содержит несколько текстовых полей и RequiredFieldValidators.
Страница содержит 2 addressControls и флажок. Если этот флажок установлен, второй контроль адресов (правильно говоря - все текстовые поля внутри addressControl ) должен быть отключен без обратной передачи и наоборот.
Мне нужно сделать это с помощью jquery без обратной передачи. Но я столкнулся с некоторыми проблемами. Одной из проблем являются RequiredFieldValidators на втором элементе управления адресами, которые становятся видимыми даже при установленном флажке (и элемент управления адресами отключен).
UPDAT2E:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1"><title>
</title><link href="/Styles/Site.css" rel="stylesheet" type="text/css" /><link href="/Styles/jqueryui.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery/jquery-1.5.1.min.js" type="text/javascript" ></script>
<script src="/scripts/jquery/jquery-ui-1.8.6.custom.min.js" type="text/javascript"></script>
<script src="/scripts/jquery/jquery.ui.datepicker-ru.js" type="text/javascript"></script>
<script type="text/javascript">
function Validator_Enable(e, v) {
if (v == false) {
e.isvalid = !v; //if disabling the validator then marked it as valid.
}
e.enabled = v;
//ValidatorValidate(e); DON'T DO
ValidatorUpdateIsValid();
}
$(document).ready(function () {
$('#MainContent_txtRegistrationDate').datepicker();
checkboxHandlerObj.init();
});
var checkboxHandlerObj =
{
init: function () {
$('#customerServices input:checkbox[class="parent"]').click(checkboxHandlerObj.parentClicked);
$('#customerServices input:checkbox[class^="parent-"]').click(checkboxHandlerObj.childClicked);
$('#MainContent_chkLegalAddress').click(checkboxHandlerObj.chkLegalAddressClick);
},
parentClicked: function () {
if ($(this).attr('checked')) {
$('#customerServices input:checkbox[class="parent-' + $(this).attr('id') + '"]').attr('checked', 'checked');
}
else {
$('#customerServices input:checkbox[class="parent-' + $(this).attr('id') + '"]').removeAttr('checked');
}
},
childClicked: function () {
var temp = $(this).attr('class').split('-');
var parentId = temp[1];
if ($(this).attr('checked')) {
$('#' + parentId).attr('checked', 'checked');
}
else {
var atLeastOneEnabled = false;
$('#customerServices input:checkbox[class="' + $(this).attr('class') + '"]').each(function () {
if ($(this).attr('checked')) {
atLeastOneEnabled = true;
}
});
if (!atLeastOneEnabled) {
$('#' + parentId).removeAttr('checked');
}
}
},
chkLegalAddressClick: function () {
if ($(this).is(':checked')) {
$('#legalAddress :input').attr('disabled', true);
var a = $('#legalAddress').find('span').attr('id');
if (a.indexOf('RequiredFieldValidator') != -1) {
$('#legalAddress').find('span').each(function () {
if ($(this).attr("controltovalidate").length > 0) {
Validator_Enable(this, false);
}
})
}
else {
$('#legalAddress :input').removeAttr('disabled');
//$('#legalAddress').find('span').attr('style', 'visibility:visible');
}
}
}
}
</script>
</head>
<body>
<form method="post" action="CustomerRegistration.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="Form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTc4MDEyMTgyMGQYAwUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgMFKWN0bDAwJEhlYWRMb2dpblZpZXckSGVhZExvZ2luU3RhdHVzJGN0bDAxBSljdGwwMCRIZWFkTG9naW5WaWV3JEhlYWRMb2dpblN0YXR1cyRjdGwwMwUhY3RsMDAkTWFpbkNvbnRlbnQkY2hrTGVnYWxBZGRyZXNzBRpjdGwwMCRtbnVOYXZpZ2F0aW9uVG9wTWVudQ8PZAUtQ3VzdG9tZXIn0Ytc0KDQtdCz0LjRgdGC0YDQsNGG0LjRjyBjdXN0b21lcidhZAUTY3RsMDAkSGVhZExvZ2luVmlldw8PZAIBZJWMKDc9T2zXH3REtHMTFcrLZQYH+1pHSEh2hOfM6MRL" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['Form1'];
if (!theForm) {
theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<div>
<fieldset>
<legend>Фактический адрес клиента</legend>
<div>
<div>Страна</div>
<span id="MainContent_ucActualAddress_RequiredFieldValidator4" style="visibility:hidden;">
<span class="error">Введите страну</span>
</span>
<div><input name="ctl00$MainContent$ucActualAddress$txtCountry" type="text" id="MainContent_ucActualAddress_txtCountry" /></div>
</div>
<div>
<div>Город</div>
<span id="MainContent_ucActualAddress_RequiredFieldValidator1" style="visibility:hidden;">
<span class="error">Введите город</span>
</span>
<div><input name="ctl00$MainContent$ucActualAddress$txtCity" type="text" id="MainContent_ucActualAddress_txtCity" /></div>
</div>
<div>
<div>Улица</div>
<span id="MainContent_ucActualAddress_RequiredFieldValidator2" style="visibility:hidden;">
<span class="error">Введите улицу</span>
</span>
<div><input name="ctl00$MainContent$ucActualAddress$txtStreet" type="text" id="MainContent_ucActualAddress_txtStreet" /></div>
</div>
<div>
<div>Дом</div>
<span id="MainContent_ucActualAddress_RequiredFieldValidator3" style="visibility:hidden;">
<span class="error">Введите корпус</span>
</span>
<div> <input name="ctl00$MainContent$ucActualAddress$txtBlock" type="text" id="MainContent_ucActualAddress_txtBlock" /></div>
</div>
<div>
<div>Строение</div>
<span id="MainContent_ucActualAddress_RequiredFieldValidator5" style="visibility:hidden;">
<span class="error">Введите юридический адрес</span>
</span>
<div><input name="ctl00$MainContent$ucActualAddress$txtBuilding" type="text" id="MainContent_ucActualAddress_txtBuilding" /></div>
</div>
</fieldset></div>
<input id="MainContent_chkLegalAddress" type="checkbox" name="ctl00$MainContent$chkLegalAddress" /><label for="MainContent_chkLegalAddress">Совпадает с фактическим адресом</label>
<div id="legalAddress">
<fieldset>
<legend>Юридический адрес клиента</legend>
<div>
<div>Страна</div>
<span id="MainContent_ucLegalAddress_RequiredFieldValidator4" style="visibility:hidden;">
<span class="error">Введите страну</span>
</span>
<div><input name="ctl00$MainContent$ucLegalAddress$txtCountry" type="text" id="MainContent_ucLegalAddress_txtCountry" /></div>
</div>
<div>
<div>Город</div>
<span id="MainContent_ucLegalAddress_RequiredFieldValidator1" style="visibility:hidden;">
<span class="error">Введите город</span>
</span>
<div><input name="ctl00$MainContent$ucLegalAddress$txtCity" type="text" id="MainContent_ucLegalAddress_txtCity" /></div>
</div>
<div>
<div>Улица</div>
<span id="MainContent_ucLegalAddress_RequiredFieldValidator2" style="visibility:hidden;">
<span class="error">Введите улицу</span>
</span>
<div><input name="ctl00$MainContent$ucLegalAddress$txtStreet" type="text" id="MainContent_ucLegalAddress_txtStreet" /></div>
</div>
<div>
<div>Дом</div>
<span id="MainContent_ucLegalAddress_RequiredFieldValidator3" style="visibility:hidden;">
<span class="error">Введите корпус</span>
</span>
<div> <input name="ctl00$MainContent$ucLegalAddress$txtBlock" type="text" id="MainContent_ucLegalAddress_txtBlock" /></div>
</div>
<div>
<div>Строение</div>
<span id="MainContent_ucLegalAddress_RequiredFieldValidator5" style="visibility:hidden;">
<span class="error">Введите юридический адрес</span>
</span>
<div><input name="ctl00$MainContent$ucLegalAddress$txtBuilding" type="text" id="MainContent_ucLegalAddress_txtBuilding" /></div>
</div>
</fieldset>
</div>
<div>
<input type="submit" name="ctl00$MainContent$btnSubmit" value="Сохранить" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$btnSubmit", "", true, "", "", false, false))" id="MainContent_btnSubmit" />
<input type="submit" name="ctl00$MainContent$btnCancel" value="Отменить" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$btnCancel", "", true, "", "", false, false))" id="MainContent_btnCancel" />
</div>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
<div align="right">
версия: 1.0.0.24109
</div>
</div>
<script type="text/javascript">
//<![CDATA[
var Page_Validators = new Array(document.getElementById("MainContent_RequiredFieldValidator1"), document.getElementById("MainContent_RequiredFieldValidator2"), document.getElementById("MainContent_RequiredFieldValidator3"), document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator4"), document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator1"), document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator2"), document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator3"), document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator5"), document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator4"), document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator1"), document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator2"), document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator3"), document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator5"), document.getElementById("MainContent_RequiredFieldValidator6"), document.getElementById("MainContent_RequiredFieldValidator7"), document.getElementById("MainContent_RequiredFieldValidator8"), document.getElementById("MainContent_RequiredFieldValidator9"), document.getElementById("MainContent_RequiredFieldValidator10"), document.getElementById("MainContent_RequiredFieldValidator11"), document.getElementById("MainContent_RequiredFieldValidator12"), document.getElementById("MainContent_RequiredFieldValidator13"), document.getElementById("MainContent_RequiredFieldValidator14"), document.getElementById("MainContent_RequiredFieldValidator15"), document.getElementById("MainContent_RequiredFieldValidator16"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var MainContent_RequiredFieldValidator1 = document.all ? document.all["MainContent_RequiredFieldValidator1"] : document.getElementById("MainContent_RequiredFieldValidator1");
MainContent_RequiredFieldValidator1.controltovalidate = "MainContent_txtShortName";
MainContent_RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator1.initialvalue = "";
var MainContent_RequiredFieldValidator2 = document.all ? document.all["MainContent_RequiredFieldValidator2"] : document.getElementById("MainContent_RequiredFieldValidator2");
MainContent_RequiredFieldValidator2.controltovalidate = "MainContent_txtPropertyForm";
MainContent_RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator2.initialvalue = "";
var MainContent_RequiredFieldValidator3 = document.all ? document.all["MainContent_RequiredFieldValidator3"] : document.getElementById("MainContent_RequiredFieldValidator3");
MainContent_RequiredFieldValidator3.controltovalidate = "MainContent_txtFullName";
MainContent_RequiredFieldValidator3.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator3.initialvalue = "";
var MainContent_ucActualAddress_RequiredFieldValidator4 = document.all ? document.all["MainContent_ucActualAddress_RequiredFieldValidator4"] : document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator4");
MainContent_ucActualAddress_RequiredFieldValidator4.controltovalidate = "MainContent_ucActualAddress_txtCountry";
MainContent_ucActualAddress_RequiredFieldValidator4.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucActualAddress_RequiredFieldValidator4.initialvalue = "";
var MainContent_ucActualAddress_RequiredFieldValidator1 = document.all ? document.all["MainContent_ucActualAddress_RequiredFieldValidator1"] : document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator1");
MainContent_ucActualAddress_RequiredFieldValidator1.controltovalidate = "MainContent_ucActualAddress_txtCity";
MainContent_ucActualAddress_RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucActualAddress_RequiredFieldValidator1.initialvalue = "";
var MainContent_ucActualAddress_RequiredFieldValidator2 = document.all ? document.all["MainContent_ucActualAddress_RequiredFieldValidator2"] : document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator2");
MainContent_ucActualAddress_RequiredFieldValidator2.controltovalidate = "MainContent_ucActualAddress_txtStreet";
MainContent_ucActualAddress_RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucActualAddress_RequiredFieldValidator2.initialvalue = "";
var MainContent_ucActualAddress_RequiredFieldValidator3 = document.all ? document.all["MainContent_ucActualAddress_RequiredFieldValidator3"] : document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator3");
MainContent_ucActualAddress_RequiredFieldValidator3.controltovalidate = "MainContent_ucActualAddress_txtBlock";
MainContent_ucActualAddress_RequiredFieldValidator3.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucActualAddress_RequiredFieldValidator3.initialvalue = "";
var MainContent_ucActualAddress_RequiredFieldValidator5 = document.all ? document.all["MainContent_ucActualAddress_RequiredFieldValidator5"] : document.getElementById("MainContent_ucActualAddress_RequiredFieldValidator5");
MainContent_ucActualAddress_RequiredFieldValidator5.controltovalidate = "MainContent_ucActualAddress_txtBuilding";
MainContent_ucActualAddress_RequiredFieldValidator5.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucActualAddress_RequiredFieldValidator5.initialvalue = "";
var MainContent_ucLegalAddress_RequiredFieldValidator4 = document.all ? document.all["MainContent_ucLegalAddress_RequiredFieldValidator4"] : document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator4");
MainContent_ucLegalAddress_RequiredFieldValidator4.controltovalidate = "MainContent_ucLegalAddress_txtCountry";
MainContent_ucLegalAddress_RequiredFieldValidator4.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucLegalAddress_RequiredFieldValidator4.initialvalue = "";
var MainContent_ucLegalAddress_RequiredFieldValidator1 = document.all ? document.all["MainContent_ucLegalAddress_RequiredFieldValidator1"] : document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator1");
MainContent_ucLegalAddress_RequiredFieldValidator1.controltovalidate = "MainContent_ucLegalAddress_txtCity";
MainContent_ucLegalAddress_RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucLegalAddress_RequiredFieldValidator1.initialvalue = "";
var MainContent_ucLegalAddress_RequiredFieldValidator2 = document.all ? document.all["MainContent_ucLegalAddress_RequiredFieldValidator2"] : document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator2");
MainContent_ucLegalAddress_RequiredFieldValidator2.controltovalidate = "MainContent_ucLegalAddress_txtStreet";
MainContent_ucLegalAddress_RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucLegalAddress_RequiredFieldValidator2.initialvalue = "";
var MainContent_ucLegalAddress_RequiredFieldValidator3 = document.all ? document.all["MainContent_ucLegalAddress_RequiredFieldValidator3"] : document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator3");
MainContent_ucLegalAddress_RequiredFieldValidator3.controltovalidate = "MainContent_ucLegalAddress_txtBlock";
MainContent_ucLegalAddress_RequiredFieldValidator3.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucLegalAddress_RequiredFieldValidator3.initialvalue = "";
var MainContent_ucLegalAddress_RequiredFieldValidator5 = document.all ? document.all["MainContent_ucLegalAddress_RequiredFieldValidator5"] : document.getElementById("MainContent_ucLegalAddress_RequiredFieldValidator5");
MainContent_ucLegalAddress_RequiredFieldValidator5.controltovalidate = "MainContent_ucLegalAddress_txtBuilding";
MainContent_ucLegalAddress_RequiredFieldValidator5.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_ucLegalAddress_RequiredFieldValidator5.initialvalue = "";
var MainContent_RequiredFieldValidator6 = document.all ? document.all["MainContent_RequiredFieldValidator6"] : document.getElementById("MainContent_RequiredFieldValidator6");
MainContent_RequiredFieldValidator6.controltovalidate = "MainContent_txtActivityScope";
MainContent_RequiredFieldValidator6.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator6.initialvalue = "";
var MainContent_RequiredFieldValidator7 = document.all ? document.all["MainContent_RequiredFieldValidator7"] : document.getElementById("MainContent_RequiredFieldValidator7");
MainContent_RequiredFieldValidator7.controltovalidate = "MainContent_txtPhone";
MainContent_RequiredFieldValidator7.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator7.initialvalue = "";
var MainContent_RequiredFieldValidator8 = document.all ? document.all["MainContent_RequiredFieldValidator8"] : document.getElementById("MainContent_RequiredFieldValidator8");
MainContent_RequiredFieldValidator8.controltovalidate = "MainContent_txtFax";
MainContent_RequiredFieldValidator8.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator8.initialvalue = "";
var MainContent_RequiredFieldValidator9 = document.all ? document.all["MainContent_RequiredFieldValidator9"] : document.getElementById("MainContent_RequiredFieldValidator9");
MainContent_RequiredFieldValidator9.controltovalidate = "MainContent_txtINN";
MainContent_RequiredFieldValidator9.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator9.initialvalue = "";
var MainContent_RequiredFieldValidator10 = document.all ? document.all["MainContent_RequiredFieldValidator10"] : document.getElementById("MainContent_RequiredFieldValidator10");
MainContent_RequiredFieldValidator10.controltovalidate = "MainContent_txtKPP";
MainContent_RequiredFieldValidator10.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator10.initialvalue = "";
var MainContent_RequiredFieldValidator11 = document.all ? document.all["MainContent_RequiredFieldValidator11"] : document.getElementById("MainContent_RequiredFieldValidator11");
MainContent_RequiredFieldValidator11.controltovalidate = "MainContent_txtSettlementAccount";
MainContent_RequiredFieldValidator11.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator11.initialvalue = "";
var MainContent_RequiredFieldValidator12 = document.all ? document.all["MainContent_RequiredFieldValidator12"] : document.getElementById("MainContent_RequiredFieldValidator12");
MainContent_RequiredFieldValidator12.controltovalidate = "MainContent_txtCorrespondentAccount";
MainContent_RequiredFieldValidator12.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator12.initialvalue = "";
var MainContent_RequiredFieldValidator13 = document.all ? document.all["MainContent_RequiredFieldValidator13"] : document.getElementById("MainContent_RequiredFieldValidator13");
MainContent_RequiredFieldValidator13.controltovalidate = "MainContent_txtBankName";
MainContent_RequiredFieldValidator13.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator13.initialvalue = "";
var MainContent_RequiredFieldValidator14 = document.all ? document.all["MainContent_RequiredFieldValidator14"] : document.getElementById("MainContent_RequiredFieldValidator14");
MainContent_RequiredFieldValidator14.controltovalidate = "MainContent_txtBIK";
MainContent_RequiredFieldValidator14.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator14.initialvalue = "";
var MainContent_RequiredFieldValidator15 = document.all ? document.all["MainContent_RequiredFieldValidator15"] : document.getElementById("MainContent_RequiredFieldValidator15");
MainContent_RequiredFieldValidator15.controltovalidate = "MainContent_txtBOSSName";
MainContent_RequiredFieldValidator15.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator15.initialvalue = "";
var MainContent_RequiredFieldValidator16 = document.all ? document.all["MainContent_RequiredFieldValidator16"] : document.getElementById("MainContent_RequiredFieldValidator16");
MainContent_RequiredFieldValidator16.controltovalidate = "MainContent_txtRegistrationDate";
MainContent_RequiredFieldValidator16.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
MainContent_RequiredFieldValidator16.initialvalue = "";
//]]>
</script>
<script type='text/javascript'>new Sys.WebForms.Menu({ element: 'mnuNavigationTopMenu', disappearAfter: 500, orientation: 'horizontal', tabIndex: 0, disabled: false });</script>
<script type="text/javascript">
//<![CDATA[
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}
//]]>
</script>
</form>
</body>
</html>