在表单中,我有多组控件,这些控件使用验证组属性进行分组。我想在客户端使用javascript在下拉列表中选择的项目的基础上动态地将验证组分配给asp.Button。
这是我正在使用的JavaScript,但它不起作用。它显示验证组未定义但实际上定义了默认组。
请指教。感谢
<script type="text/JavaScript">
function NextClicked() {
var _ddlStatus = document.getElementById("<%=ddl.ClientID%>");
var _selectedIndex = _ddlStatus.selectedIndex;
var _btn = document.getElementById("<%=btnNext.ClientID%>");
alert(_btn.ValidationGroup); // here in messge it shows undefiend, yet I have defiend a group in button as default.
if (_selectedIndex == 1) {
_btn.ValidationGroup = "G1";
}
else
if (_selectedIndex == 2) {
_btn.ValidationGroup = "G2";
}
}
答案 0 :(得分:5)
function changeValidationGrop(){
var _ddlStatus = document.getElementById("<%=ddl.ClientID%>");
var _selectedIndex = _ddlStatus.selectedIndex;
var btn = document.getElementById("<%=btnNext.ClientID%>");
var newValGroup;
if(_selectedIndex == 1)
newValGroup="G1";
else
newValGroup="G2";
btn.onclick = function(){
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("btnNext", "", true, newValGroup, "", false, false));
}
}