views:

15

answers:

1

hi,

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

A: 

Hello, try this:

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));                
    }           
}    
Tim Schmelter