Wednesday, March 28, 2012

Accessing server-side Datatable object from client-side javascript?

I am working on a control that generates 2D charts (line,bar,pie,etc) using VML (for now) to draw the charts client-side. I am new to Javascript and still cant figure out how to access the data I need to graph from the javascript side. I am currently using a Sys.Data.Datable on the client side as test data (building the table manually in javascript) and it works fine but I cannot figure how to pass a datatable from the server to the control extension behavior?

I have read/seen code on the forums on how to do this using a web-service but I am really looking at a more generic approach where people could just bind a datatable to the control via the properties or in code so they can use their business logic layer functionality without having to write web-services.

Let's say I have the name of the page object/variable holding the datatable (from properties of control) how would I access this object as a Sys.Data.Datatable in Javascript? Would I need to use some kind of converter?

(hope I explained myself correctly and this makes sense to someone hehe)

Thanks in Advance

Pascal

Hello Pascal:

> I am new to Javascript and still cant figure out how to access the data I need to graph from the javascript side.

Strictly speaking, you can't! It is the server-side code that renders client-side code, so what you can do is actually the reverse: write the datatable to javascript.

Here is a topic that can give some hints:http://forums.asp.net/thread/1285185.aspx

This said, please feel free to go deeper with your question if needed.

-LV


Thanks for the quick reply btw :)

Here is some example of what I am trying to do (not actual code):

Lets say I have some ASPX page code like...

<script language="VB"> Private sub Page_Load() dim myTable as System.Data.Datatable ... populate table ... End sub</script><html> <body> <atlas:ScriptManager runat="server" ID="PageScriptManager" EnablePartialRendering="True"> </atlas:ScriptManager> <asp:Panel ID="ChartPanel" runat="server" Height="300" Width="400" /> <cc1:ChartPanelExtender ID="ChartPanelExtender1" runat="server" > <cc1:ChartPanelProperties ChartTitle="This is my Graph!" TargetControlID="ChartPanel" ChartType="0" ChartHeight="100" ChartWidth="300" ChartBackColor="#FF3A00" ChartTitleFontFamily="Arial Black" ChartTitleFontSize="20" ChartTitleFontWeight="Normal" ChartTitleTextAlign="Right" /> </cc1:ChartPanelExtender> </body></html>

The ChartPanelExtender is an atlas control extender that has its functionality (chart graphing) in its ChartPanelBehavior.js javascript file. What I would like to do is access that myTable from inside the javascript behavior file? Is that possible?

Thanks in advance,

Pascal

No comments:

Post a Comment