Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  


Pass string from .NET to Javascript
To pass static string content from .NET to Javascript, you can create a static method or propery on a static class that returns an encoded javascript string using HttpUtility.JavaScriptStringEncode:

In static class 'MyStaticClass':

public static string GetJSString()
return HttpUtility.JavaScriptStringEncode("result of method or constant here");

Then include it on your page as follows:
<script type="text/javascript">
var str = '@MyStaticClass.GetJSString()';

Created By: amos 8/31/2016 1:53:56 PM