Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pass a value from javascript to c#

Posted on 2007-03-21
6
Medium Priority
?
300 Views
Last Modified: 2010-08-05
I need to retrieve a value calculated using javascript back to my c# code.

The javascript code is here:

      function calculateShipping(){            
            var numberTotal = new NumberFormat( parseFloat(Shipping.value) + parseFloat(subTotal) );
            numberTotal.setPlaces(2);
            
            totalPrice.innerHTML = baseCurrency + numberTotal.toFormatted();
      }

I need to pass the numerTotal back to c# when an imagebutton is clicked on a page.

Thanks!!
0
Comment
Question by:infodigger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 18764183
That is NOT possible.
C# is running ONCE before the page is displayed to browser on web server side. When the C# has finished and all the output html page source text is flushed to browser, then is the browser starting to render the html page and run any embedded script in the page html text.
The script on the browser page cannot access  ANYTHING on web server side.
All the a browser can do to server is to request a new URL to be loaded into page or submit form data that unloads the actual window content.
The only exception that browser cand do is use hidden techniques, like iframe communication in the background, or AJAX, or <img> or Image() object manipulation that do call another aspx web server page in the background.
So your image click can have an image src attribute set in that way that some aspx page on server side is called to update the Session variables to the new calculated Total.

But why do you want do that at all! At next postback are all form fields submitted anyway. So put your Total in some hidden field and fetch it from there at next post back when you do the next recalculation for that page.



0
 
LVL 4

Expert Comment

by:Cyber-Drugs
ID: 18764349
One possible way is with an AJAX Call...

Make AJAX call a page, eg:

www.yoursite.com/getvalue.aspx?myvalue=1234

Where:

"getvalue.aspx" is a c# page to retreive your JS value
"myvalue" is the POST variable to hold your value
"1234" is your POST value

Have AJAX call that page, but do not bother to display it. I do this method with PHP quite often, if you like I can pull out the code I use for this to help you along.

Hope that helps.
0
 
LVL 4

Expert Comment

by:Cyber-Drugs
ID: 18764356
And after further reading Zvonko's reply, I see her mentioned the same thing... sorry Zvonko :o)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Expert Comment

by:Zvonko
ID: 18764493
No problem :)
0
 

Author Comment

by:infodigger
ID: 18764508
Thank you all for your help!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 18764569
You are welcome.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question