How to pass a variable from asp.net to JavaScript?
Use javascript tag
<script>
var var1 = @var1;
var var2 = @var2;
</script>
Use hidden field
<input type="hidden" value="@var1" id="h_var1"/>
<input type="hidden" value="@var2" id="h_var2" />`
in js
$(function()
{
var var1 = $("#h_var1").val();
var var2 = $("#h_var2").val();
}
3.Retrieve data via ajax using json
var var1;
var var2;
$.get(url,function(result)
{
var1 = result.var1; var2 = result.var2;
}
@var syntax depend of your view engine. It maybe <%= Var1 %>