简体   繁体   中英

How to Get JavaScript value From c# back end

Hi guy i have a javasciprt will create a value , is that any way for me to capture the value in my c# back end code.

function GetKey(){ return Key; } //key is a combination value 

Thank you

C# in backend

public String MyVariable;

MyVariable = "Some Value";

ASPX

<%=MyVariable %>
  1. via ajax
  2. You can put it into your aspx page code and pass it to your js (if you are using asp). If Key is an object, you can serialize it to json string and use JSON parser to deserialize it. If it is a basic type, use <%= Key %> in your asp page is OK. (Note you cannot put the code in your js file)
 <script type="text/javascript"> var key = JSON.parse('<%=JsonConvert.SerializeObject(someObj.GetKey()) %>'); //now you can use key in your js logic </script> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM