Well Im new in ASP.net , and I expect that the javascript function should update the variable every time I update the table "Table1" in my database, what it does it updates the value just once.
I will apreciate your help.
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript" language="javascript" >
- //<![CDATA[
- var chart = new AnyChart('../anychart_files/swf/AnyChart.swf');
- chart.setXMLFile('TemperatureXMLFile.xml');
- chart.write('container');
- var airtempjs = "<%=airtempcs%>" // The string airtempcs is defined in codebehind
- function update() {
- chart.updatePointData("Thermometer", "Temp", { value: (airtempjs) });
- }
- setInterval(update, 400);
- //]]>
- </script>
the code behind
Expand|Select|Wrap|Line Numbers
- public string airtempcs;
- protected void Page_Load(object sender, EventArgs e)
- {
- //Create the command and the Connections Objects
- string connectionString = ConfigurationManager.ConnectionStrings["ChartTestConnectionString"].ConnectionString;
- SqlConnection con = new SqlConnection(connectionString);
- SqlCommand cmd = new SqlCommand("SELECT AirTemp FROM Table1", con);
- //Open the connection and get the DataReader
- con.Open();
- SqlDataReader reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- airtempcs = reader.GetDouble(0).ToString();
- }
- reader.Close();
- con.Close();
- }