0

I want to use a Javascript variable in C#, is it possible, how do I go about it? Thanks

5
  • 2
    Please be more specific. What do you want to do exactly? Commented May 24, 2011 at 11:15
  • 5
    This is a bit like saying I want to read vinyl with a CD player. Commented May 24, 2011 at 11:18
  • 1
    I want to check the value of a JS variable (after some client side validations), after server trip on page load, so that based on that value I can perform some actions. Commented May 24, 2011 at 11:18
  • @Andreas Zoltan: You probably mean laserdisc player, or have you ever seen a 5" vinyl? Commented May 24, 2011 at 11:23
  • @takrl - hmmmm - laserdisc + vinyl - I think it's got legs you know. Commented May 24, 2011 at 11:39

3 Answers 3

8

best way is to write that variable to a cookie, and read from C#.

but you can also use:

  • send that variable asynchronously
  • send that variable as part of a POST
Sign up to request clarification or add additional context in comments.

Comments

3

I believe you would be interested in the value held by the variable and to make it available to the C# code as you suggest it needs to be posted to the server.

So you can assign the value to a Hidden Field which you can retrieve at the server end and use the value

Comments

1

Use asp.net hidden field and update the value on client side using JS. Then you can easily access that field on server side since it would be a server control

Comments

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.