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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

This worked for me. Thanks. I had issues changing the ValidationGroup for the validationSummary so I ended up adding a ValidationSummary for each group.
I tried this solution, but my validation is not firing when the user clicks the submit button

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.