Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Javascript as Follows
JavaScript
function onLoad() {
var options = {
sourceLanguage: ['en'],
destinationLanguage: ['kn'],
}
How to pass the value for Destination Language from coding on Page Load event in asp.net.
Posted
Updated 24-Aug-15 2:18am
v2
Comments
Sergey Alexandrovich Kryukov 24-Aug-15 8:56am    
You never ever pass a value from server side to client side. You just generate all resource, including JavaScript, in response to HTTP request from client side and sent them back to client side, and the JavaScript text can be parameterized using usual ASP.NET technique, the way everything else is done in ASP.NET.
—SA

Several ways:

1: You can do it via a service call using ajax or some other web call that does not post back the page.
2: You can add a hidden field to the form. Populate that from JS then read it from the post
3: You can post it as a partial post back (there are several ways to do this, but mainly calling __postback(sometarget,yourVar); )

That covers most of the ways. The most common is the hidden field method as most people use the value in the postback (or button.click) event.

EDIT:

Actually - as your object is more complex that just a string, you could use a JSON style stringify. You would need to parse it to an object from a JSON string before you could really use it, though
 
Share this answer
 
v2
 
Share this answer
 
v2
As your .net page_load runs first and generates the html to send to the browser, so the page_load has finished before your javascript begins so you can only pass that data to your server-code after the page has processed.

The solution that best fits what it is you're probably wanting to do is to call a web service, or use "page methods" to pass the data to a server method and from there you'll probably store it in the session to that subsequent requests have access to it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900