0

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;
mcvision
  • 21
  • 6
  • That's because `myjavascript.js` is 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 or `fetch()` it from the client-side JS. The first way is very simple: insert `` above your existing script tag, then use `theID` in your script. –  May 22 '20 at 13:43
  • Does this answer your question? [Passing variable from ASP.net to JavaScript](https://stackoverflow.com/questions/10540217/passing-variable-from-asp-net-to-javascript) –  May 22 '20 at 13:46
  • can u please demonstrate with the example I gave? – mcvision May 22 '20 at 14:22

0 Answers0