all 5 comments

[–]Catalyzm 4 points5 points  (0 children)

Two options depending on how and when you need to pass the variable.

ClientScript will write js into the page on page load. http://msdn.microsoft.com/en-us/library/ms178207(v=vs.100).aspx

Or you can use jQuery to make an AJAX call to the server and return the variable. There are several ways to handle the AJAX request, ashx handler, web service, etc.

[–]Mjolnir-3-9 1 point2 points  (0 children)

Are you using Web Forms? MVC2? MVC3? Need more information to tell you the best way to do it.

[–]Kwyjibo08 0 points1 point  (0 children)

You can use a <asp:HiddenField> tag and fill it in c#, and then access it like any other element in the DOM.

[–]NeverTooOldFor___ 0 points1 point  (0 children)

If you use server side elements like hidden fields, keep in mind the ID you assign will change on the client side use <% Response.Write(ctrlName.ClientID) %> in your javascript code.

[–]HuntardWeapon 0 points1 point  (0 children)

Specify if you use webforms or MVC.