Pass asp.net value to javascript block
<p>I need to pass values from my asp.net code to a javascript code block in the page. </p>

<p>I know at least two ways to do this:</p>

<pre><code>&lt;script runat=server&gt;
int a = 42;
protected override void OnInit(EventArgs e)
{
   lbl.Text = "42";
}
&lt;/script&gt;

&lt;script&gt;
   var a = &lt;%= a %&gt;;
   var b = &lt;asp:Literal runat=server id=lbl&gt;/&gt;;
   alert("the meaning of life=" + a + " or " + b);
&lt;/script&gt;
</code></pre>

<p>But is there a better way in asp.net WebForms to bind the value of a variable in asp.net code to a javascript block? Both of these seem messy because they don't support intellisense. </p>
