2

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

haansi
  • 5,470
  • 21
  • 63
  • 91

1 Answers1

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

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • 2
    This worked for me. Thanks. I had issues changing the ValidationGroup for the validationSummary so I ended up adding a ValidationSummary for each group. – JCallico Aug 16 '11 at 16:09
  • I tried this solution, but my validation is not firing when the user clicks the submit button – Michael Kniskern Apr 18 '13 at 16:41