views:

39

answers:

2

Yikes .. I feel like this one should be obvious, but I guess I'm brainblocking here - Even so much that I don't know what to search for in google :S Oh well, SO to the rescue :)

Say I got this .aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyPage.aspx.cs" Inherits="MyPage" %>
<script type="text/javascript">

//<!-- I want to inject a JSON string here, which is generated per side-request -->

function doStuffToMyData(){
   // .....
}

</script>

Any idea how I can inject a JSON string here? I got no problem generating the string, or parsing it in the browser..

It could be there's an easier way to do this? I basically want to manipulate the looks of the side, depending on changes to this data, so I figured it would be easiest to have the data as a JSON string.

Thanks in advance :)

+1  A: 
var myJson = '<%= "{}" %>';
Max Toro
Thanks.. I knew it was simple :) Can only accept one answer though, so going for the one that was 27 seconds faster than yours :)
cwap
+2  A: 

It should be something like:

var json = <%= variableName %>

Assuming that in your codebehind, you've declared something like:

string variableName = Json.Encode(something);
Daniel T.