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

Jim Lawrence accessd at shaw.ca
Tue Dec 11 14:33:19 CST 2012


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


_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com




More information about the dba-VB mailing list