I would like to get the value of an ASP.NET control from inside of a javascript file. I know how to do this when the javascript is on the aspx page, but not when it is in a js file. Example:
<head>
<script type="text/javascript">
alert('<%= lbl_test.Text %>'); //alerts the text of the ASP.NET label
</script>
<script type="text/javascript" src="Scripts/test.js" /> //alerts "<%= lbl_test.Text" %>
</head>
In this example test.js only has alert('<%= lbl_test.Text %>'); in it.
Is there anyway for me to reproduce the behavior in the first piece of javascript in the js file?
You cannot do it like this you will have to either
or
http://social.msdn.microsoft.com/Forums/en-US/jscript/thread/c706d380-9688-4758-9d7e-9522d59d5855