Adding Javascript to ASPX page with C# -


i have javascript code , want add page in default.aspx.cs.

i tried following:

string sb = @" <script type='text/javascript'>         var chart;          var chartdata = [{'year': 2005,'income': 23.5,'expenses': 18.1},             {'year': 2006,'income': 26.2,'expenses': 22.8},             {'year': 2007, 'income': 30.1, 'expenses': 23.9 },             {'year': 2008,'income': 29.5,'expenses': 25.1},             {'year': 2009,'income': 24.6,'expenses': 25}             ];               amcharts.ready(function () {             chart = new amcharts.amserialchart();             chart.dataprovider = chartdata;             chart.categoryfield = 'year';             chart.startduration = 1;             chart.plotareabordercolor = '#dadada';             chart.plotareaborderalpha = 1;chart.rotate = true;var categoryaxis = chart.categoryaxis;             categoryaxis.gridposition = 'start';             categoryaxis.gridalpha = 0.1;             categoryaxis.axisalpha = 0;var valueaxis = new amcharts.valueaxis();             valueaxis.axisalpha = 0;             valueaxis.gridalpha = 0.1;             valueaxis.position = 'top';             chart.addvalueaxis(valueaxis);             var graph1 = new amcharts.amgraph();             graph1.type = 'column';             graph1.title = 'income';             graph1.valuefield = 'income';             graph1.balloontext = 'income:[[value]]';             graph1.linealpha = 0;             graph1.fillcolors = '#add981';             graph1.fillalphas = 1;             chart.addgraph(graph1);             var graph2 = new amcharts.amgraph();             graph2.type = 'column';             graph2.title = 'expenses';             graph2.valuefield = 'expenses';             graph2.balloontext = 'expenses:[[value]]';             graph2.linealpha = 0;             graph2.fillcolors = '#81acd9';             graph2.fillalphas = 1;             chart.addgraph(graph2);var legend = new amcharts.amlegend();             chart.addlegend(legend); chart.creditsposition = 'top-right';             chart.write('chartdiv');         });     </script>";           scriptmanager.registerstartupscript(this.page,           this.gettype(), "myfun1", sb, false); 

the code works when directly added aspx page, when try , try other code can't run on page.

i fill values database . must dynamically

edit: solved problem. added label on page , wrote code

        label5.text = sb; 

the problem code has comments. makes of javascript code invalid when render browser, remove comments , try again.

for debugging, can try render script literal control first, , see script error in console.

string sb = @" <script type='text/javascript'>     var chart;     var chartdata = [{ 'year': 2005, 'income': 23.5,'expenses': 18.1},     amcharts.ready(function () {         chart = new amcharts.amserialchart();          chart.dataprovider = chartdata;                         chart.categoryfield = 'year';          chart.startduration = 1;          chart.plotareabordercolor = '#dadada';          chart.plotareaborderalpha = 1;          chart.rotate = true;         var categoryaxis = chart.categoryaxis;                         categoryaxis.gridposition = 'start';                         categoryaxis.gridalpha = 0.1;                         categoryaxis.axisalpha = 0;         var valueaxis = new amcharts.valueaxis();         valueaxis.axisalpha = 0;         valueaxis.gridalpha = 0.1;         valueaxis.position = 'top';         chart.addvalueaxis(valueaxis);         var graph1 = new amcharts.amgraph();                         graph1.type = 'column';                         graph1.title = 'income';                         graph1.valuefield = 'income';                         graph1.balloontext = 'income:[[value]]';                         graph1.linealpha = 0;                         graph1.fillcolors = '#add981';graph1.fillalphas = 1;                        chart.addgraph(graph1);         var graph2 = new amcharts.amgraph();                        graph2.type = 'column';                         graph2.title = 'expenses';                         graph2.valuefield = 'expenses';                         graph2.balloontext = 'expenses:[[value]]';                         graph2.linealpha = 0;                         graph2.fillcolors = '#81acd9';                        graph2.fillalphas = 1;               chart.addgraph(graph2);         var legend = new amcharts.amlegend();                         chart.addlegend(legend);                         chart.creditsposition = 'top-right';          chart.write('chartdiv');                 });       </script>";   scriptmanager.registerstartupscript(this.page,    this.gettype(), "myfun1", sb, false); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -