Using C# code inside JavaScript code






4.57/5 (5 votes)
if you are working in a page that has a master page, and you want to reference the server controls from JavaScript you must use their ClientID instead of the ID property, so in order to use C# code within JavaScript code, you will have to surround your C# code with the <%= and %>, and this is the example.
var txtBox = document.getElementById(‘<%=txtName.ClientID%>’);remember this code is available only if your JavaScript code was in an .aspx file not a .js file