ASP.NET - changing validation group of button with javascript on client side

Asked By Haansi Haansi on 15-Jun-10 01:23 AM
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";       
      }
    }
</script>    
Santhosh N replied to Haansi Haansi on 15-Jun-10 02:04 AM
The validationGroup of any control is not rendered in the html of the page when served to the client and hence javascript could not recognize that as a property of the control..
You need to assign that property in the javascript and access or you need to be passing that in client click explicitly..

document.getElementById("<%=btnNext.ClientID%>").ValidationGroup = "urValGroup";
Haansi Haansi replied to Santhosh N on 15-Jun-10 02:14 AM
Thanks Santhosh for guiding,

You are right I just confirmed it validation group is rendered as a part of javascript and not as a property.

but if I set it as you guided will it work with validation controls ?
 
To be more spacific, how validation controls will know I want this validation group to be used for validation ?

Please guide.

thanks
Santhosh N replied to Haansi Haansi on 15-Jun-10 02:19 AM
You need to be setting it up for all the controls participating in the validation and I recommend you to handle this on server side as its easy unless anything really required you to do on client side..