[dba-VB] ASP.NET - pass data from .cs to .js

Gustav Brock gustav at cactus.dk
Wed Dec 12 12:03:37 CST 2012


Hi Jim

I went to a Microsoft Web Camp today and watched a demo of SignalR. 

At its best, it establishes a duplex socket connection between the server
and all clients connected at a given moment offering real-time update of the
clients - individually or all - at a dozen or so of simple code lines using
JavaScript client side and one of several libraries server side. Very
impressive and very promising. It can presently handle about 40.000
connected clients with a tiny CPU load on the server - the network
connection is the bottleneck. This is the beta; the final version is aimed
at 500.000 simultaneous connections.

For older servers or clients, it offers about four downgrade communication
methods which are negotiated automatically - your code stays the same. It is
almost like magic.

/gustav


-----Oprindelig meddelelse-----
Fra: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] På vegne af Jim Lawrence
Sendt: 11. december 2012 21:33
Til: 'Discussion concerning Visual Basic and related programming issues.'
Emne: Re: [dba-VB] ASP.NET - pass data from .cs to .js

Hi Gustav:

Definitely interesting. I will download the library and take a close look. 

It will be a bit different from most FE webpages as they do not need
synchronize connections but given the examples they show, for game use and
for creating and maintaining a VPN connection, the library might be very
useful. I would like to see how the program negotiates and maintains a
secure socket between a client and a server.

Jim 

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Tuesday, December 11, 2012 6:29 AM
To: 'Discussion concerning Visual Basic and related programming issues.'
Subject: Re: [dba-VB] ASP.NET - pass data from .cs to .js

Hi all

Is SignalR familiar to anyone:

http://signalr.net/

<quote>
.. the ability to have your server-side code push content to the connected
clients as it happens, in real-time.
</quode>

/gustav

-----Oprindelig meddelelse-----
Fra: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] På vegne af Gustav Brock
Sendt: 21. november 2012 17:39
Til: 'Discussion concerning Visual Basic and related programming issues.'
Emne: [dba-VB] ASP.NET - pass data from .cs to .js

Hi all

I have an ASP.NET winform project (.aspx) with a code-behind .cs file and an
included .js file for client side code.
The client side code is nothing special, only that it minimizes the
round-trip to the server which I found slowed down the page when run on a
smart-phone with GSM data link (not WiFi).

How can I pass data from the .cs code to the .js code?

Right now I write some client side script at Page_Load:

<c#>
private void RegisterScripts()
{
    // Output the reference to the .js file.
    Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "jScript",
"/ClientScript.js");
 
    // Output the variables.
    StringBuilder sb = new StringBuilder();
    sb.Append("<script type=\"text/javascript\"
language=\"javascript\">\n");
    sb.AppendFormat("var optionsOne = new
Array(\"{0}\",\"{1}\",\"{2}\");\n", optionsAll[0,0], optionsAll[0,1],
optionsAll[0,2]);
    sb.AppendFormat("var optionsTwo = new
Array(\"{0}\",\"{1}\",\"{2}\");\n", optionsAll[1,0], optionsAll[1,1],
optionsAll[1,2]);
    sb.AppendFormat("var optionsThree = new
Array(\"{0}\",\"{1}\",\"{2}\");\n", optionsAll[2,0], optionsAll[2,1],
optionsAll[2,2]);
    sb.AppendFormat("var answerComments = new Array(\"{0}\",\"{1}\");\n",
answerComments[0], answerComments[1]);
    sb.AppendFormat("var alertEnterEmail = \"{0}\";\n", alertEnterEmail);
    sb.Append("</script>\n");
    Page.ClientScript.RegisterClientScriptBlock(GetType(), "fillOptions",
sb.ToString()); } </c#>

This works fine and dandy as the data (the arrays and variables) are static
during a session (but not between sessions) as these are retrieved once from
the database also at Page_Load.

But the scriptblock is visible at client side if the user selects "View
source" in the browser and I would prefer it not to be.
Also, the method of writing code lines from code seems sort of primitive to
me.
Would there be a better/easier/smarter way?

/gustav





More information about the dba-VB mailing list