title: How to access a Button's ValidationGroup property
body: <p>I need to access the ValidationGroup value of a button in a javascript function.
  The button is part of a nested grid.  I set the ValidationGroup value during the RowDataBound event for the button and the Dropdown controls.  Shown below:</p>
  
  <pre><code>protected void UserGroupGridView_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          try
          {
              if (e.Row.RowType == DataControlRowType.DataRow)
              {
                  int tiGroupID = Convert.ToInt32(UserGroupGridView.DataKeys[e.Row.RowIndex].Value.ToString());
                  m_strUserID = CommonMethods.ParseUserID(User.Identity.Name);
                  GridView tgvGroupMember = (GridView)e.Row.FindControl("GroupMemberGridView");
                  populateGroupMemberGrid(tgvGroupMember, tiGroupID);
  
                  //Get the Footer controls that have the new entry data
                  Control tFooterControls = CommonMethods.getFooterControls(tgvGroupMember);                
                  DropDownList tddlRecipientNames = tFooterControls.FindControl("mggvDDLMemberName") as DropDownList;
                  m_strXmlTableData = m_pagingClient.GetAllPossibleGroupMembers(m_strUserID, tiGroupID);
                  DataTable tdtAllGroupMembers = CommonMethods.ParseXML(m_strXmlTableData);
                  tddlRecipientNames.DataSource = tdtAllGroupMembers;
                  tddlRecipientNames.DataTextField = tdtAllGroupMembers.Columns["MemberName"].ToString();
                  tddlRecipientNames.DataValueField = tdtAllGroupMembers.Columns["MemberID"].ToString();
                  tddlRecipientNames.DataBind();
                  tddlRecipientNames.Items.Insert(0, new ListItem("", "0"));//This is needed for the jquery-chosen dropdown to add data-holder text
                  tddlRecipientNames.ValidationGroup = "DDLVal_" + tiGroupID.ToString();
  
                  Button tbtnAdd = tFooterControls.FindControl("mggvAddButton") as Button;
                  tbtnAdd.ValidationGroup = "DDLVal_" + tiGroupID.ToString();
              }
          }
          catch (Exception ex)
          {
              //TO DO: Response.Redirect("~/Error.aspx");
          }
      }
  </code></pre>
  
  <p>This is the markup for the Dropdown and Button:</p>
  
  <pre><code>&lt;asp:DropDownList ID="mggvDDLMemberName" runat="server" ClientIDMode="Static" class="chosen-single" data-placeholder="Choose member…"&gt;
  &lt;/asp:DropDownList&gt;
  &lt;asp:RequiredFieldValidator ID="ReqValueDDLMemberInsert" runat="server" InitialValue="0"                                         ControlToValidate="mggvDDLMemberName" ErrorMessage="Selection required." CssClass="message-error-dropdown"&gt;
  &lt;/asp:RequiredFieldValidator&gt;
  
  &lt;asp:Button ID="mggvAddButton" runat="server" CommandName="Add" Text="Add Member" Width="90%" ClientIDMode="Static" CssClass="gridActionbutton" CausesValidation="true" OnClientClick="return Validate(this);" &gt;
  &lt;/asp:Button&gt;
  </code></pre>
  
  <p>When the button is clicked, I call the client-side function, Validate(this).
  This is the Validate function:</p>
  
  <pre><code>function Validate(ClientID) {
    valgroup = ClientID.Validators[0].validationGroup;
  //THIS IS THE PROBLEM.  valgroup is null?
    alert(valgroup);
   if (Page_ClientValidate(valgroup)) {
  //   alert('it is valid');
     return true;
   }
   else {
   //  alert('No valid');
     return false;
   }
  </code></pre>
  
  <p>How to you access the ValidationGroup property of the button?</p>
  
  <p><strong>UPDATE</strong>
  Playing around with different jquery methods, this is what i am found...
  I can get the ID of the sending button using this:</p>
  
  <pre><code>function Validate(ClientID)
  {
      var val = $(ClientID).attr('id');
      alert(val); //this returns the id of the button (mggvAddButton)
  
      //This returns the DropDown list id, entries, etc.
      //This dropdown is beside the button.
      var val = $(ClientID).parent().parent().html();
      alert(val);
  
      //When I try to get the id of the dropdown, I get 'undefined.
      var val = $(ClientID).parent().parent().attr('id');
      alert(val);
  }
  </code></pre>
  
  <p>Why can't it find the id of the dropdown?  It is in the html!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Adding the entire nested grid to better explain what I need to do...</p>
  
  <pre><code>&lt;div id="div&lt;%# Eval("GroupID") %&gt;" style="display:none"&gt;
  &lt;asp:GridView ID="GroupMemberGridView" runat="server" AutoGenerateColumns="false" OnRowDeleting="GroupMemberGridView_RowDeleting" 
  OnRowCommand="GroupMemberGridView_RowCommand" CssClass="grid" ShowFooter="true"&gt;
  &lt;Columns&gt;
  &lt;asp:TemplateField HeaderText="MemberID"&gt;
  &lt;ItemTemplate&gt;
  &lt;asp:Label ID="mggvLblMemberID" runat="server" Text='&lt;%# Bind("MemberID") %&gt;'&gt;&lt;/asp:Label&gt;
  &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  &lt;asp:TemplateField HeaderText="Member Name" ItemStyle-Wrap="false"&gt; 
  &lt;ItemTemplate&gt;
  &lt;asp:Label ID="mggvLblMemberName" runat="server" Text='&lt;%# Bind("MemberName") %&gt;'&gt;&lt;/asp:Label&gt;
  &lt;/ItemTemplate&gt;               
  &lt;FooterTemplate&gt;
  &lt;asp:DropDownList ID="mggvDDLMemberName" runat="server" ClientIDMode="Static" class="chosen-single" data-placeholder="Choose member…"&gt;
  &lt;/asp:DropDownList&gt;
  &lt;asp:RequiredFieldValidator ID="ReqValueDDLMemberInsert" runat="server" InitialValue="0" ControlToValidate="mggvDDLMemberName" ValidationGroup="InsertMemberValidation" ErrorMessage="Selection required." CssClass="message-error-dropdown"&gt;
  &lt;/asp:RequiredFieldValidator&gt;
  &lt;/FooterTemplate&gt;
  &lt;/asp:TemplateField&gt;
  &lt;asp:TemplateField HeaderText="Active Device(s)"&gt;                   
  &lt;ItemTemplate&gt;
  &lt;asp:Label ID="mggvLblActiveDevice" runat="server" Text='&lt;%# (Boolean.Parse(Eval("ActiveDevice").ToString())) ? "Yes" : "No" %&gt;'&gt;&lt;/asp:Label&gt;
  &lt;/ItemTemplate&gt;                   
  &lt;/asp:TemplateField&gt;
  &lt;asp:TemplateField HeaderText="Action" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center"&gt;
  &lt;ItemTemplate&gt;
  &lt;asp:Button ID="mggvDeleteButton" runat="server" CausesValidation="False" CommandName="Delete"                                               Text="Delete" CssClass="gridActionbutton"  OnClientClick="return confirm('Are you sure you want to delete this Group Member?')" &gt;
  &lt;/asp:Button&gt;
  &lt;/ItemTemplate&gt;                                     
  &lt;FooterTemplate&gt;
  &lt;asp:Button ID="mggvAddButton" runat="server" CommandName="Add" Text="Add Member" Width="90%" ClientIDMode="Static" CssClass="gridActionbutton" CausesValidation="true" ValidationGroup="InsertMemberValidation" OnClientClick="return Validate(this);" &gt;
  &lt;/asp:Button&gt;
  &lt;/FooterTemplate&gt;
  &lt;/asp:TemplateField&gt;
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After some debugging, I have learned that the first nested grid and all of its controls can be easily accessed. However, the second nested grid has none of the control ids set.</p>
  
  <p>The javascript function:</p>
  
  <pre><code>function Validate(sender)
  {
      var e = document.getElementById("mggvDDLMemberName");
      var strSel = "The Value is: " + e.options[e.selectedIndex].value + " and text is: " + e.options[e.selectedIndex].text;
  
      alert(strSel);
  }
  </code></pre>
  
  <p>When I click the 'Add' button for the FIRST nested grid and select a value in the Dropdown, The above javascript function correctly displays the data.</p>
  
  <p>When I click the 'Add button for the SECOND nested grid and select a value in the Dropdown. The above javascript function displays the Value as 0 and text is empty.</p>
  
  <p>However, in BOTH cases the member is successfully added to the group and displayed in the list after the Add button is clicked.</p>
  
  <p>So it appears that regardless of which 'Add' button is clicked, only the first nested grid data is read in this javascript function.  But in the code-behind, the Add event can correctly determine which nested grid to add the member to.</p>
  
  <p>This is the GroupMember (nested grid) add row command:</p>
  
  <pre><code>protected void GroupMemberGridView_RowCommand(object sender, GridViewCommandEventArgs e)
   {
      try
      {
         if (e.CommandName.Equals("Add"))
         {                 
            //Get the Footer controls that have the new entry data
            GridView tgvGroupMember = (GridView)sender;
            Control tFooterControls = CommonMethods.getFooterControls(tgvGroupMember);
            int tiMemberID = Convert.ToInt32((tFooterControls.FindControl("mggvDDLMemberName") as DropDownList).SelectedItem.Value);
            int tiGroupID = Convert.ToInt32((tgvGroupMember.Parent.FindControl("uggvLblGroupID") as Label).Text);
  
            //Insert into the database
            m_pagingClient.InsertGroupMember(tiGroupID, tiMemberID);
  
            //Rebind the grid with the new data
            populateGroupGrid();
          }
       }
       catch (Exception ex)
       {
          //TO DO: Response.Redirect("~/Error.aspx");
        }
  }
  </code></pre>
  
  <p>The method above determines which Member grid triggered the event and go from there.</p>
  
  <p>I need to do the same on the client-side in the javascript function to validate the DDL entry.</p>