p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   variables (http://p2p.wrox.com/showthread.php?t=70483)

daniel.mihalcea September 9th, 2008 06:01 AM

How can I pass javascript variables in c#?
The problem is that I have a group of variables that in the first place I have to import them in javascript, do some work with them, end then call them back in c# to make a request to a server.
Thank You.

Old Pedant September 9th, 2008 07:06 PM

There are only two ways to pass data to *ANY* server side application: Via a query string or via POST data. And in both cases, you must do so by "hitting" a URL on the server.

In general, with ASP.NET, you would use POST data. And that means you must send the data by submitting a <FORM>.

So the first answer is simple: Use a form field (i.e., <INPUT NAME=whatever>).

And the expansion on that answer is also simple: Use hidden form field(s) and then use JavaScript coding to copy the value of the JS variable(s) into the form field value(s).

I assume this is related to your question about panning an image, so you could just do:
    document.forms[0].panX.value = panX;
    document.forms[0].panY.value = panY;
assuming you have hidden form fields named panX and panY and javascript variables of the same name. (No reason for them to be same; just makes sense for them to be, for housekeeping.)

Now when the user submits the <FORM> (presumably, by clicking on your ZOOM button), those values will be available to your C# code via simply

All times are GMT -4. The time now is 08:26 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.