This must be a dead simple one.
When I put my javascript in MyPage.aspx, I can access server controls and variables by putting them inside <%= %>
When I move this javascript out of MyPage.aspx and put it in MyPage.js, <%= %> makes not a lot of sense. What am I doing wrong.
Here's an example of what I'm trying to do:
When I take out the javascript out of the above file, <%= hidMyVar %> throws an exception:
When I put my javascript in MyPage.aspx, I can access server controls and variables by putting them inside <%= %>
When I move this javascript out of MyPage.aspx and put it in MyPage.js, <%= %> makes not a lot of sense. What am I doing wrong.
Here's an example of what I'm trying to do:
Code:
//----------------------------------
// MyPage.aspx
//----------------------------------
<html>
<head>
<script type='text/javascript'>
var x = document.getElementById('<%= hidMyVar %>').value;
alert(x)
</scripty>
</head>
<body>
<form>
<input type='hidden' id='hidMyVar' runat='server' />
</form>
</body>
</html>
When I take out the javascript out of the above file, <%= hidMyVar %> throws an exception:
Code:
//----------------------------------
// MyPage.js
//----------------------------------
var x = document.getElementById('<%= hidMyVar %>').value;
alert(x)
//----------------------------------
//----------------------------------
// MyPage.aspx
//----------------------------------
<html>
<head>
<script src="MyPage.js" type="text/javascript"></script>
</head>
<body>
<form>
<input type='hidden' id='hidMyVar' runat='server' />
</form>
</body>
</html>