ASP.Net | Read Values from Javascript

Today I started checking out some videos about Windows CardSpace and ASP.Net for logging in and I saw how he used javascript to get client side input and use it in ASP.Net in the C# code.

First you need to create a HiddenField on your webForm and name it TokenField (any name would actually do)

<asp:HiddenField ID=”TokenField” runat=”server” />

To set the Hidden Field value in JavaScript use the following code:



var textbox = document.getElementById(“TokenField”);
textbox.value = value;

To get the data stored in TokenField and use it in ASP.Net code behind use the next:

string token = TokenField.value;

Voila, you just used Javascipt and C# to use each other’s variables. I know that this might be basic for some of you, but for me it’s a life saver 🙂 As for CardSpace, I think it isn’t much in use on websites. What do you think?

For more info re CardSpace check this online tutorial or here

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *