I have some script in javascript file call myjavascript.js and I want to get the content of asp:Label on my page. inside the head of my page i have linked the javascript file to the page. but am not able to reference the asp:Label om my page in myjavascript.js file. please help below is my code
//on my HTML page
<head>
<script type="text/javascript" src="myjavascript.js"></script>
</head>
//in the myjavascript.js file
var totalamounttopay = document.getElementById('<%=Me.lblfinalgrosstotal.ClientID%>').innerText;
myjavascript.jsis sent as-is to the client and therefore asp.net never replaces the<%tag content. To make server-side data available to the client, you can either put it in an inline script orfetch()it from the client-side JS. The first way is very simple: insert<script>const theID = "<%=Me.lblfinalgrosstotal.ClientID%>";</script>above your existing script tag, then usetheIDin your script.