Thanks for all your help so far I have made the following changes
This is the code on run:
<body>
<form method="post" action="ResultsDetails.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzQ5NzY1NjU0ZGRuWExqnYyaWn0sRggTtOIdHlawc3aZvdNLKpOq0D+uMQ==" />
</div>
<div id="placeholder" style="width:600px;height:300px;"></div>
<script type="text/javascript">
//<![CDATA[
var arrayOfResults = new Array();
arrayOfResults[0] = 2;
arrayOfResults[1] = 4;
arrayOfResults[2] = 5;
arrayOfResults[3] = 1;
arrayOfResults[4] = 4;
var numberArray = Array(1, 2, 3, 4, 5);
//]]>
</script>
</form>
<div id="codeGeneration">
<script type="text/javascript">
$(document).ready(function () {
$.plot($('#placeholder'), [arrayOfResults, numberArray]);
});
</script>
</div>
</body>
The plot method is being run but i keep gettin the error saying that the arrays havent been initalised?
im using
ClientScript.RegisterStartupScript(this.GetType(), "run", sb.ToString() ,true);
to write the array code.
Sloved I did the following
private void generateJScriptArray(int[] array)
{
StringBuilder sb = new StringBuilder();
sb.Append("var arrayOfResults = Array(); \n ");
for (int i = 0; i < array.Length; i++)
{
sb.Append("arrayOfResults[" + i + "] = " + array[i] + "; \n ");
}
sb.Append("var numberArray = Array(1, 2, 3, 4, 5); \n");
sb.Append("alert(numberArray[0]); \n");
sb.Append("$(document).ready(function () { \n $.plot($('#placeholder'), [arrayOfResults, numberArray]); \n });");
ClientScript.RegisterStartupScript(this.GetType(), "run", sb.ToString() ,true);
}
Thanks to all who helped.
Use the ScriptManager to register the startup script. Something like this: