Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
How to use javascript variable into aspx.cs code in ASP.NET.

Want to use javascript variable value into ASPX.CS file in asp.net.

Thanks,
Mangesh :-)
Posted

it depends on how you want to use the variable. You could pass a javascript variable via an Ajax call, such as using a Page Method. You could pass the variable as a query string. You could use any HTML element that has the runat=server attribute which will create a GenericHtml object in you code-behind
 
Share this answer
 
 
Share this answer
 
Hello,

you can set the value of hidden field in java script and then access that value in aspx.cs page,

can try this......
 
Share this answer
 
You can use C# variable to JavaScript but it is difficult to use JavaScript variable to C#...
You can use HiddenFiled .....
 
Share this answer
 
v2
If you want to access a variable whose value will be manipulated in javascript using HiddenField is the best. But if you want to access multiple variables from Javascript in your code behind, I recommend using JSON object and pass it as a parameter to your method.
 
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