Is there anyway passing variable from C# to javascript dynamically?

I want to send a variable from C# to Javascript dynamic.

I have tried the following code down below.

But the method or the variable will only read once.

How can I make it work ?

in aspx.cs

    public partial class WebForm2 : System.Web.UI.Page     {         internal static string timer = "false";          protected void Page_Load(object sender, EventArgs e)         {          }         public string MyMethod()         {             return timer;         }     } 

in aspx

<script>     function GetMyName()     {         setInterval(function() {             dynamic xx = "<%=MyMethod()%>";             console.log(xx);         }, 1000);     } </script>