title: Fetch ASP.NET label control through JavaScript the right way?
body: <p>Good day. I am trying to fetch an asp.net label control's text value using javascript. However the control id is returned as null when I use</p>
  
  <pre><code>var a = document.getElementById('&lt;%= lblTreatyNo.ClientID %&gt;').innerText;
  </code></pre>
  
  <p>However it does work when I use the full name from source like</p>
  
  <pre><code>var a = document.getElementById('ctl00_ContentPlaceHolder1_lblTreatyNo').innerText;
  </code></pre>
  
  <p>I am using master pages in my site design. I want to know the correct way of fetching this. Isn't there a way not to use the full name from the source file?</p>
  
  <p>Update here is my code sample</p>
  
  <pre><code>&lt;asp:Label ID="lblTreatyNo" runat="server"&gt;&lt;/asp:Label&gt;    
  &lt;asp:Button ID="btnNewSec" runat="server" OnClientClick="javascript:void(window.open ('ft_newsec.aspx?ftid='+document.getElementById('ctl00_ContentPlaceHolder1_lblTreatyNo').innerHTML+'',null,'height=220,width=300,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes')); return false;" Text="Add New Company" CausesValidation="False" Width="155px" /&gt;
  </code></pre>