abc cba
abc cba

Reputation: 2633

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

Upvotes: 0

Views: 975

Answers (2)

Chris Li
Chris Li

Reputation: 3725

  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>

Upvotes: 2

Rab
Rab

Reputation: 35572

C# in backend

public String MyVariable;

MyVariable = "Some Value";

ASPX

<%=MyVariable %>

Upvotes: 3

Related Questions