Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,
I hava a site build with Asp.Net. I want to transfer a variables or a list to a javascript direct from c# code. Also, the javascript exist, all i want to do is to "inject" somehow in that javascript a new line with the variables so i can use them direct in javascript. If it is another easy way to do something like this please help me.

Thanks
Posted

One thing you can do is, try making an ajax call to the server & on the ajax success bind the parameters from the server to any gobal variable in your javascript. This would help you out.

C#
$.ajax({
url: //your call to server,
data: //if any needed to pass as parameter
sucess: function(data){ //here data is the received values from server call method
 //do something like bind values to a global variable to be reused any where in the script.
}

});

Thanks
:)
 
Share this answer
 
"Inject" not somehow, but using a script function parameters. If you don't have those parameters, introduce them. :-)

—SA
 
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