asp.net - changing validation group of button with javascript on client side - Stack Overflow

In a form I have multiple group of controls which are grouped using validation group property. I want t

In a form I have multiple group of controls which are grouped using validation group property. I want to assign validation group to asp.Button dynamically on client side using javascript on the base of item selected in drop down list.

Here is JavaScript which I am using, but it is not working. It shows validation group undefined but actually a default group is defined.

Please advice me. thanks

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

In a form I have multiple group of controls which are grouped using validation group property. I want to assign validation group to asp.Button dynamically on client side using javascript on the base of item selected in drop down list.

Here is JavaScript which I am using, but it is not working. It shows validation group undefined but actually a default group is defined.

Please advice me. thanks

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

Share Improve this question asked Jun 15, 2010 at 5:28 haansihaansi 5,76022 gold badges66 silver badges91 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6
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));                
    }           
}    

Still no documentation

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744316933a4568229.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信