0

I have a function in C# which can be called like this:

string result = CachedLanguageItems.GetLabel("RandomLabel").Value

It returns me the cached value of the RandomLabel.
Now I want to use this method in Javascript like this:

var result = <%= CachedLanguageItems.GetLabel("RandomLabel").Value %>

This is also working. It returns me the cached value of RandomLabel.

The problem that I am facing now is, that I am not able to pass a javascript variable to the method instead of a hard coded string. e.g.:

var javascriptVariable= "RandomLabel"
var result = <%= CachedLanguageItems.GetLabel(javascriptVariable).Value %>

Can somebody tell me how to pass the javascript variable correctly to the embedded c# call of the method?

Do I have to escape the embedded code for this?
Is this even possible?

Thanks for the help.

3
  • What environment are you using? What does 'embedded' mean in this context? Commented Sep 22, 2015 at 10:14
  • @rmorring, this looks like ASPX which is the .NET counterpart to PHP. Commented Sep 22, 2015 at 10:16
  • Read tag descriptions before adding! This is not relates to embedded devices! Commented Sep 22, 2015 at 13:13

1 Answer 1

4

This is not possible. The C# code is evaluated on the server before the HTML is shipped to the browser. The JS code runs on the client (the browser). What you could do it write a small service which you call via AJAX that returns the value you need.

Please read my related answer to this on How to use PHP with Visual Studio

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your quick response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.