ASP .Net Code Within JavaScript
17 July 2009
7,297 views
No Comment
Simple thing really, often times you might need to use a asp .net variable within javascript code. How you do that?
- Declare the variable as protected(public will do as well)
- Set the code on JavaScript to use the Asp .net Variable within JavaScript
Example:
Declare the variable as protected like this.
protected string myVar;
On your code you would initialize it somewhere. e.g. myVar=”Great webmaster forum webcosmoForums.com”;
Set the code on JavaScript to use the Asp .net Variable within JavaScript e.g.
<script type=”text/javascript”>
var aVar= ‘<%=myVar %>’; /*= here is shorthand for Response.Write*/
alert(aVar);
</script>










Leave your response!