Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access C# Variable From JavaScript

I have a public property in my code behind named Tab which I'm trying to access in the pages aspx file with javascript but I'm not sure how to get the right value.

This gives me the value I want

alert('<% Response.Write(this.Tab); %>');

This does not

 var x = <% =this.Tab %>;
 alert(x); 

Any ideas?

like image 805
John Doe Avatar asked Dec 17 '22 03:12

John Doe


1 Answers

If you view the source you are probably seeing

var x = mystring;

I would guess you want the quotes too

var x = "<%= this.Tab %>";

Instead of having code inline, why don't you look at RegisterStartUpScript or RegisterClientScriptBlock.

like image 106
epascarello Avatar answered Dec 18 '22 16:12

epascarello