I am having problems setting JavaScript variables on the Server Side in ASP.Net Web Forms (Not MVC) using Master Pages.
Basically I want to do something like this:
<script type="text/javascript">
var z = '<%# Request.QueryString["Env"] %>';
</script>
After I run the code I see: var z=’’;
I also tried:
var z = ‘<%= Request.QueryString[“Env”] %>’;
After I run that code I get the following error so I assume that is not correct:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).
I have been doing mainly MVC development these past few years so I am not sure what I am doing wrong.
Please let me know.
Thanks
I think it is a good idea to place the javascript just before closing the body tag instead of head tag. Then you can use <%= syntax.