Author |
Topic |
Sparked
Starting Member
5 Posts |
Posted - 2012-03-03 : 09:23:41
|
This is a question I have been trying to answer for a long time but haven't had any luck. I'm not sure if I'm being stupid or not.I would like to learn of the best practice in asp.net for interacting with a sql server database in a secure way with javascript. I can write some functions in javascript that will do what I want but I don't know how to pass the information from SQL server to the javascript code. I thought dynamically generating the code from the server using ClientScriptManager might be the answer but that doesn't work. I really need to be able to pass an array from the server to the client which the client javascript could then process.Another potential solution is to populate a hidden table on the client page but this sounds messy.Any help would be much appreciated. |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-03-03 : 11:35:48
|
I'd recommend looking at Microsoft's AJAX components, they're designed to manage this kind of interaction (asynchronous data retrieval). Even if you don't use it the techniques involved and the philosophy behind it is instructive. |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2012-03-03 : 11:55:39
|
First why do you want javascript to interact with sql server ?After Monday and Tuesday even the calendar says W T F .... |
 |
|
Sparked
Starting Member
5 Posts |
Posted - 2012-03-03 : 12:08:03
|
Thanks, robvolk, I'll check it out.@Sachin.Nand: Because there is data that I'd like to visualize that is held on a SQL server. I don't want javascript to interact directly with SQL Server. I want to use the all the features that javascript and HTML5 offer to present this data. Querying server-side is easy enough, so is programming with javascript. Its getting the data from one place to the other that is giving me problems. I will probably be able to find a solution but what I really want to know is the best practice. |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2012-03-03 : 12:29:17
|
Not sure whether we are on the same page..In your first post you said "...but I don't know how to pass the information from SQL server to the javascript code".So I thought you want to know the ways a javascript can interact with SQL Server.But in the second post you said ".. I want to use the all the features that javascript and HTML5 offer to present this data."Both these things are quite different.Javascript should only be used to format and validate the data on the client side but passing the information and presenting to javascript should be only done through your data access layer(can be a DLL or a WCF service or an ORM) and nothing else.After Monday and Tuesday even the calendar says W T F .... |
 |
|
Sparked
Starting Member
5 Posts |
Posted - 2012-03-03 : 12:47:54
|
Yes, sorry for the confusion. I'm new to web programming and it shows. I certainly don't want javascript to interact with SQL Server directly. However, I want javascript to be the code that presents the data in an interactive way. This chart using the d3 library is a good example: [url]http://mbostock.github.com/d3/ex/population.html[/url]Buttons would execute server-side code to query the database based upon field values, but how to get the data to the javascript?I guess this is where the data access layer comes in? Is this the topic I should research? |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2012-03-03 : 13:02:09
|
Well it all depends on what you decide to use as DAL.Sometime back I had used a WCF service which interacted with json objects.If you are not aware of what json is then you can start here http://www.json.org/js.htmlAfter Monday and Tuesday even the calendar says W T F .... |
 |
|
Sparked
Starting Member
5 Posts |
Posted - 2012-03-03 : 13:22:08
|
Hmm. Rather than use the built-in data connections in .net programming I've always created my own class that connects using OleDB and returns a datatable or array. This is what I've done here by habit. I can then populate a gridview with it, if I want, for example. Once that exists on the page I can use javascript to do what I want with the data. The bit I'm unsure about is how to make that datatable or array, etc, visible to the client. Thank you for the link. Yes, I've touched upon JSON before but never used it practically. And thanks for your help on this. I can't help but think I'm missing something obvious. |
 |
|
Sachin.Nand
2937 Posts |
|
Sparked
Starting Member
5 Posts |
Posted - 2012-03-03 : 13:43:09
|
Thank you, that looks very useful. |
 |
|
|