Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 9th, 2008, 06:01 AM
Authorized User
 
Join Date: Aug 2008
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default variables

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 September 9th, 2008, 07:06 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

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
    panX.text
and
    panY.text





Similar Threads
Thread Thread Starter Forum Replies Last Post
using variables webgrphx Classic ASP Basics 3 April 11th, 2007 06:46 PM
Global Variables in C# su C# 2 December 11th, 2006 06:18 PM
Passing Variables silve1999 Pro Java 1 June 15th, 2006 12:54 PM
undifined variables bogins BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 19th, 2004 06:19 PM





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