Best Practices - set jQuery property from Code-Behind
<p>I need to set a single property in a jQuery command using a value that is calculated in the code-behind. My initial thought was to just use <code>&lt;%= %&gt;</code> to access it like this:</p>

<p>.aspx</p>

<pre><code>&lt;script type="text/javascript" language="javascript"&gt;
$('.sparklines').sparkline('html', {
    fillColor: 'transparent',
    normalRangeMin: '0',
    normalRangeMax: &lt;%= NormalRangeMax() %&gt;
});
&lt;/script&gt;
</code></pre>

<p>.aspx.cs</p>

<pre><code>protected string NormalRangeMax() {
    // Calculate the value.
}
</code></pre>

<p>It smells odd to have to call from the ASPX page to just get a single value though. Not to mention I have an entire method that does a small calculation just to populate a single property.</p>

<p>One alternative would be to create the entire <code>&lt;script&gt;</code> block in the code-behind using <code>clientScriptManager.RegisterClientScriptBlock</code>. But I really don't like putting entire chunks of JavaScript in the code-behind since its, well, JavaScript.</p>

<p>Maybe if I end up having many of these methods I can just put then in a partial class so at least they are physically separate from the rest of the code.</p>

<p>What method would you recommend as being easy to understand and easy to maintain?</p>
