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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s