title: ASP.NET, jquery get hidden fields values on asp:button click
body: <p>I have two hidden fields which get latitude and longitude on a button click using jQuery. Below is the code working good, I want to calculate the distance using these lat and lng. For testing Im trying to show the hidden field value in textbox and label, you can see that in jQuery. However if I set the property as <strong>OnClientClick="return true"</strong> in button code I dont see anything working. If I set as <strong>return false</strong> I can see the values but not in label.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function () {
          geocoder = new google.maps.Geocoder();
  
          $("#btn").on("click", function () {
              var address = $("#tbCity").val();
              geocoder.geocode({ 'address': address }, function (results, status) {
                  if (status == google.maps.GeocoderStatus.OK) {
                      var lat = results[0].geometry.location.lat();
                      var lng = results[0].geometry.location.lng();
  
                      //alert(latitude + ", " + longitude);
                  }
  
                  $('#latitude').val(lat);
                  $('#longitude').val(lng);
                  $('#txtBox1').val($('#latitude').val());   
                  $('#txtBox2').val($('#longitude').val());
                  $('#lbl1').val($('#latitude').val());
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>ASP.NET code</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
       Address: &lt;asp:TextBox ID="tbCity" runat="server"&gt;&lt;/asp:TextBox&gt;        
       &lt;asp:HiddenField ID="latitude" runat="server" /&gt;
       &lt;asp:HiddenField ID="longitude" runat="server" /&gt;
       &lt;br /&gt;&lt;br /&gt;
       &lt;asp:TextBox ID="txtBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
       &lt;asp:TextBox ID="txtBox2" runat="server"&gt;&lt;/asp:TextBox&gt;
       &lt;asp:Button ID="btn" runat="server" Text="Button" OnClientClick="return false"  OnClick="btn_Click"/&gt;
       &lt;br /&gt;
       &lt;asp:Label ID="lbl1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Generated HTML code</p>
  
  <pre><code>    &lt;form method="post" action="GetCoordinates.aspx" id="form2"&gt;
           &lt;div class="aspNetHidden"&gt;
              &lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"   value="/wEPDwUKLTQyNTI1OTg4N2RkGXXMNhEfkB7Ie6CVb4YTwItExhof/IkHpdh6f26grxc="&gt;
           &lt;/div&gt;
          &lt;div class="aspNetHidden"&gt;
               &lt;input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"  value="/wEdAAeWsE0BRbQ0wjG1w60jqqdcq35qZMbaIVF3xrHN6flGNv+/yOgSqO/6irT+NtXuduQ93hcP/MBYTB//29SOqPZfAcmup7kkBHBfToLV39zc8Mj6eKFRARwXIj8IINCyLct0YEyduRVooG3ha/OFYKMXG9w1RtaOWHfqueLltflOGuLDyL1I+PDm4fhtuLq7nGM="&gt;
          &lt;/div&gt;
          Address: &lt;input name="tbCity" type="text" id="Text1"&gt;        
                   &lt;input type="hidden" name="latitude" id="Hidden1" value="-34.92862119999999"&gt;
                   &lt;input type="hidden" name="longitude" id="Hidden2" value="138.5999594"&gt;       
                   &lt;input name="txtBox1" type="text" id="Text2"&gt;
                   &lt;input name="txtBox2" type="text" id="Text3"&gt;
                   &lt;input type="submit" name="btn" value="Button" onclick="return false;" id="Submit1"&gt;        
          &lt;span id="Span1"&gt;Label&lt;/span&gt;
       &lt;/form&gt;
  </code></pre>
  
  <p>Updated code</p>
  
  <pre><code>&lt;form method="post" action="GetCoordinates.aspx" id="form1"&gt;
  &lt;div class="aspNetHidden"&gt;
  &lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEyMTQwNTA2MzFkZBAUxV0uM2MNtGYuUK81rFUmmAiaeLksG6QHsLB3zWtZ"&gt;
  &lt;/div&gt;
  &lt;div class="aspNetHidden"&gt;
  &lt;input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAci5mChXqDZFj3vgdOgA11rq35qZMbaIVF3xrHN6flGNv+/yOgSqO/6irT+NtXuduQ93hcP/MBYTB//29SOqPZfAcmup7kkBHBfToLV39zc8Mj6eKFRARwXIj8IINCyLct0YEyduRVooG3ha/OFYKMX/9MR/+s9E/Yu8cFwBQ5SCqt4ngV9Kdj9/OR/r/Q8mvQ="&gt;
  &lt;/div&gt;
      Address: &lt;input name="tbCity" type="text" id="tbCity"&gt;        
      &lt;input type="hidden" name="latitude" id="latitude" value="-34.92862119999999"&gt;
      &lt;input type="hidden" name="longitude" id="longitude" value="138.5999594"&gt;     
      &lt;br&gt;&lt;br&gt;
      &lt;input name="txtBox1" type="text" id="txtBox1"&gt;
      &lt;input name="txtBox2" type="text" id="txtBox2"&gt;        
      &lt;input name="btn" type="button" id="btn" value="showCode"&gt;
      &lt;span id="lbl1"&gt;Label&lt;/span&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Updated .Net code</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
      Address: &lt;asp:TextBox ID="tbCity" ClientIDMode="Static"  runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:HiddenField ID="latitude" ClientIDMode="Static" runat="server" /&gt;
      &lt;asp:HiddenField ID="longitude" ClientIDMode="Static"  runat="server" /&gt;
      &lt;br /&gt;&lt;br /&gt;
      &lt;asp:TextBox ID="txtBox1" ClientIDMode="Static"  runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:TextBox ID="txtBox2" ClientIDMode="Static"  runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;input type="button"   id="btn" runat="server"  value="showCode" /&gt;
      &lt;br /&gt;
      &lt;asp:Label ID="lbl1" runat="server" ClientIDMode="Static" Text="Label"&gt;&lt;/asp:Label&gt;
  &lt;/form&gt;
  </code></pre>