title: Radiobutton changed value doesnt update hiddenfield?
body: <p>I've got a hidden field in an asp.net gridview like so:</p>
  
  <pre><code> &lt;asp:TemplateField&gt;
        &lt;ItemTemplate&gt;
            &lt;input type="hidden" value="0" id="hdnIsChanged" runat="server" /&gt;
        &lt;/ItemTemplate&gt;
   &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>The hidden field is used so that if another field on my gridview is changed I can update the value of this hidden field with the value 1.  That way when I click a "Save" button I can loop through the rows of my gridview and only call my database update routine if and only if the hiddenField.Value = "1".</p>
  
  <p>I set this field in the <code>rowdatabound</code> event of the gridview easily with something like this for a textbox:</p>
  
  <pre><code>    HtmlInputHidden hiddenField = (HtmlInputHidden)e.Row.FindControl("hdnIsChanged"); //get handle on hidden row isDirty
      TextBox notes = (TextBox)e.Row.FindControl("txtNotes"); //get notes
  
  //assign onchange / onclick event handlers when something is changed set hidden field to 1
      notes.Attributes.Add("onchange", "document.getElementById('" + hiddenField.ClientID + "').value=1");
  </code></pre>
  
  <p>This works fine for textboxes and drop downs but I also have a radiobuttonlist in my grid.  When I change for instance 3 rows in my gridview by just selecting the radio button, it always ONLY updates 1.  It appears the hidden field doesnt get set correctly.  I thought I could set it correctly like this:</p>
  
  <pre><code>RadioButtonList rbl = (RadioButtonList)e.Row.FindControl("rbAnswer"); //get answer
  
                  //assign onchange / onclick event handlers when something is changed set hidden field to 1
                    foreach(ListItem li in rbl.Items)
                      li.Attributes.Add("onclick", "document.getElementById('" + hiddenField.ClientID + "').value=1");
  </code></pre>
  
  <p>This doesn't appear to work and consider clicks for each radio button.  As I said if I update three rows by just clicking the radiobutton in each row and then click my save button it only calls the update routine once.  It appears the hidden field does not get the value 1.</p>
  
  <p>Can anyone help?</p>
  
  <h2>Edit</h2>
  
  <p>Just in case here is my entire grid view control:</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="myPanel" runat="server" UpdateMode="Always" &gt;
                       &lt;ContentTemplate&gt;
                      &lt;asp:GridView ID="gvLineItems" runat="server" AllowSorting="True" 
                          AlternatingRowStyle-BackColor="#e5f1fa" AutoGenerateColumns="False" 
                          BackColor="#E8E8E8" CellPadding="4" DataKeyNames="ID" Font-Size="Small" 
                          GridLines="Horizontal" HeaderStyle-BackColor="#4B6C9E" 
                          HeaderStyle-ForeColor="White" ShowFooter="True" Width="700px" 
                               onrowdatabound="gvLineItems_RowDataBound" 
                               onrowcreated="gvLineItems_RowCreated"&gt;
                          &lt;AlternatingRowStyle BackColor="#E5F1FA" /&gt;
                          &lt;Columns&gt;
                              &lt;asp:TemplateField&gt;
                                   &lt;ItemTemplate&gt;
                                        &lt;input type="hidden" value="0" id="hdnIsChanged" runat="server" /&gt;
                                   &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField&gt;
                                  &lt;HeaderTemplate&gt;
                                      &lt;asp:CheckBox ID="HeaderLevelCheckBox" runat="server" 
                                          onclick="toggleSelection(this);" ToolTip="Select / Deselect all rows?" /&gt;
                                  &lt;/HeaderTemplate&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:CheckBox ID="chkSelector" runat="server" onclick="ChangeRowColor(this)" 
                                          ToolTip="Select row?" /&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;ItemStyle HorizontalAlign="Center" Width="1%" /&gt;
                                  &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                              &lt;/asp:TemplateField&gt;
  
                              &lt;asp:TemplateField Visible="False"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:Label ID="lblID" runat="server" style="display:none" 
                                          Text='&lt;%# DataBinder.Eval(Container, "DataItem.ID") %&gt;' Width=".05px"&gt;&lt;/asp:Label&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;ItemStyle Width="1%" /&gt;
                                  &lt;ControlStyle Width="0px" /&gt;
                                  &lt;HeaderStyle Width="0px" /&gt;
                              &lt;/asp:TemplateField&gt;
  
                                &lt;asp:TemplateField HeaderText="#"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:Label ID="lblSortOrder" runat="server" 
                                          Text='&lt;%# DataBinder.Eval(Container, "DataItem.SortOrder") %&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/ItemTemplate&gt;
                                   &lt;FooterStyle HorizontalAlign="Center" /&gt;
                                   &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                   &lt;ItemStyle HorizontalAlign="Center" /&gt;
                              &lt;/asp:TemplateField&gt;
  
                               &lt;asp:TemplateField HeaderText="Validation"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:Label ID="lblValidationItem" runat="server" ToolTip="Type of validation."
                                          Text='&lt;%# DataBinder.Eval(Container, "DataItem.ValidationItem") %&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/ItemTemplate&gt;
                                   &lt;FooterStyle HorizontalAlign="Center" /&gt;
                                   &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                   &lt;ItemStyle HorizontalAlign="Center" /&gt;
                              &lt;/asp:TemplateField&gt;
  
                              &lt;asp:TemplateField HeaderText="Test"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:Label ID="lblTest" runat="server" ToolTip="Type of test."
                                          Text='&lt;%# DataBinder.Eval(Container, "DataItem.Test") %&gt;'&gt;&lt;/asp:Label&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;FooterStyle HorizontalAlign="Center" /&gt;
                                  &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                  &lt;ItemStyle HorizontalAlign="Center" /&gt;
                              &lt;/asp:TemplateField&gt;
  
                              &lt;asp:TemplateField HeaderText="Method"&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;table&gt;
                                          &lt;tbody&gt;
                                              &lt;tr&gt;
                                                  &lt;td&gt; &lt;asp:Label ID="lblMethod" Font-Bold="true" runat="server" ToolTip="Method / Question"
                                          Text='&lt;%# DataBinder.Eval(Container, "DataItem.Method") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                                              &lt;/tr&gt;
                                              &lt;tr&gt;
                                              &lt;td&gt;
                                               &lt;asp:Label ID="lblMethodNotes" CssClass="tiny" runat="server" ToolTip="Specifications / Notes"
                                          Text='&lt;%# DataBinder.Eval(Container, "DataItem.MethodNotes") %&gt;'&gt;&lt;/asp:Label&gt;
                                              &lt;/td&gt;
                                              &lt;/tr&gt;
                                          &lt;/tbody&gt;
                                      &lt;/table&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;ControlStyle Width="250px" /&gt;
                                  &lt;FooterStyle HorizontalAlign="Left" /&gt;
                                  &lt;HeaderStyle HorizontalAlign="Left" Width="250px" /&gt;
                                  &lt;ItemStyle HorizontalAlign="Left" Width="250px" Wrap="True" /&gt;
                              &lt;/asp:TemplateField&gt;
  
                              &lt;asp:TemplateField HeaderText="Answer"&gt;
                              &lt;ItemTemplate&gt;
                                 &lt;div id="dMainAnswer"&gt;
                                  &lt;asp:RadioButtonList ToolTip="Please provide an answer to the method." AutoPostBack="true" RepeatDirection="Horizontal" ID="rbAnswer" runat="server" SelectedValue='&lt;%# DataBinder.Eval(Container, "DataItem.AnswerID")%&gt;' OnSelectedIndexChanged="rbAnswer_SelectedIndexChanged"&gt;
                                      &lt;asp:ListItem Text="Yes" Value="Yes" style="color:green;"&gt;&lt;/asp:ListItem&gt;
                                      &lt;asp:ListItem Text="No" Value="No" style="color:red;"&gt;&lt;/asp:ListItem&gt;
                                      &lt;asp:ListItem Text="N/A" Value="N/A"&gt;&lt;/asp:ListItem&gt;
                                      &lt;asp:ListItem Value="" Text="" style="display: none" /&gt;
                                  &lt;/asp:RadioButtonList&gt;
                                     &lt;asp:Panel ID="pnlAnswer" runat="server" Visible="false"&gt;
                                         &lt;div id="dMainAnswerResponsibleType"&gt;
                                              &lt;asp:RadioButtonList ID="rbRespType" ToolTip="Select responsible contact type." runat="server" RepeatDirection="Horizontal" AutoPostBack="true" SelectedValue='&lt;%# DataBinder.Eval(Container, "DataItem.ResponsiblePartyType")%&gt;' OnSelectedIndexChanged="rbRespType_SelectedIndexChanged"&gt;
                                                  &lt;asp:ListItem Selected="True" Text="SE" Value="SE"&gt;SE&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Text="Other" Value="Other"&gt;Other&lt;/asp:ListItem&gt;
                                                  &lt;asp:ListItem Value="" Text="" style="display: none" /&gt;
                                              &lt;/asp:RadioButtonList&gt;
                                          &lt;/div&gt;
                                          &lt;div id="dMainAnswerResponsible"&gt;
                                               &lt;asp:DropDownList ID="ddlEmployees" runat="server" 
                                                  DataSource="&lt;%# GetEmployees() %&gt;" SelectedValue='&lt;%# Eval("SEContact") %&gt;' DataTextField="FullName" Width="75px"
                                                  DataValueField="FullName" 
                                                  ToolTip="Select the SE responsible party."&gt;
                                              &lt;/asp:DropDownList&gt;
                                              &lt;asp:TextBox ID="txtContact" Text='&lt;%# Eval("ResponsiblePartyContact") %&gt;' Width="75px" MaxLength="50" runat="server" ToolTip="Enter the responsible contact name." Visible="false"&gt;&lt;/asp:TextBox&gt;
                                          &lt;/div&gt;
                                     &lt;/asp:Panel&gt;
                                 &lt;/div&gt;
                              &lt;/ItemTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Notes"&gt;
                              &lt;ItemTemplate&gt;
                                 &lt;asp:TextBox MaxLength="5000" runat="server" ToolTip="Enter any additional notes." ID="txtNotes" TextMode="MultiLine" Text='&lt;%# DataBinder.Eval(Container, "DataItem.Notes") %&gt;'&gt;&lt;/asp:TextBox&gt;
                              &lt;/ItemTemplate&gt;
                                  &lt;ControlStyle Font-Names="Arial" /&gt;
                                  &lt;FooterStyle HorizontalAlign="Left" /&gt;
                                  &lt;HeaderStyle HorizontalAlign="Left" /&gt;
                                  &lt;ItemStyle HorizontalAlign="Left" /&gt;
                              &lt;/asp:TemplateField&gt;
                          &lt;/Columns&gt;
                          &lt;HeaderStyle BackColor="#4B6C9E" ForeColor="White" /&gt;
                      &lt;/asp:GridView&gt;
  
                    &lt;div style="width:100%;text-align:center;"&gt;
                      &lt;asp:Label ID="lblLineItemMessage" runat="server"&gt;&lt;/asp:Label&gt;
                      &lt;asp:UpdateProgress AssociatedUpdatePanelID="myPanel" DisplayAfter="1" ID="udProgress" runat="server" Visible="True" DynamicLayout="True"&gt;
                          &lt;ProgressTemplate&gt;
                              &lt;img style="border-style:none;" src="images/ajax-loader.gif" alt="loading" /&gt;
                          &lt;/ProgressTemplate&gt;
                      &lt;/asp:UpdateProgress&gt;
                  &lt;/div&gt;
                  &lt;/ContentTemplate&gt;
                  &lt;Triggers&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="ddlTypes" /&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="ddlValidations" /&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="ddlTests" /&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="ddlJobs" /&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="rbMethod" /&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="TreeView1" /&gt;
                  &lt;/Triggers&gt;
                  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>I even tried some jquery to get an alert:</p>
  
  <pre><code>  $(function () {
              $("#&lt;%=gvLineItems.ClientID %&gt; input[type=radio]").click(function () {
                  alert("hi");
              });
          });
  </code></pre>
  
  <p>But I dont think that is right because when I click a radio button I am not seeing any alert.  I also need to update the field <code>hdnIsChanged</code> the hiddenfield with the value 1 when a radio button item from the radiobuttonlist <code>rbAnswer</code> is clicked.  I am ok to do this in jquery but could use some help.  The hiddenfield hdnIsChanged and the radiobuttonlist rbAnswer are both inside an asp.net gridview.</p>