You can generate a server-side script and paste the value into it:
StringBuilder sb = new StringBuilder(); sb.Append("<script type=\"text/javascript\""); sb.Append("var someFunc = function(){"); sb.AppendFormat("alert('{0}');", importantServerSideValue); sb.Append("};"); sb.Append("</script>"); Page.ClientScript.RegisterClientScriptBlock("genScript", sb.ToString());
Or put the value in a hidden form element on the page and access it from the client side Javascript.
<asp:HtmlInputHidden id="hiddenField" runat="server" /> // And in the code-behind hiddenField.Value = importantServerSideValue;
Justin niessner
source share