user959128
user959128

Reputation: 957

How to use asp variable in JavaScript?

I have stored text box value in JavaScript variable

 var strline1side1 = document.frmartwork.side1textbox1.value;

and then saved that value in JavaScript cookie

 document.cookie="lineside1="+strline1side1+";path=/;";

now I want to save this cookie in asp variable.

I tried this:

 <%=ASPVariable%> = document.frmartwork.side1textbox1.value;

but its not working

How can I do this?

Upvotes: 0

Views: 2354

Answers (4)

immutabl
immutabl

Reputation: 6903

You could store the value in a formfield e.g. hidden field and then access its contents by checking the Request.Forms collection

...
myCookieValue = Request.Forms("side1textbox1")
...

Upvotes: 1

AnthonyWJones
AnthonyWJones

Reputation: 189457

Fascinating array of answers here is my 2 pennies worth

<%

    Dim aspVar

    aspVar = Request.Cookies("lineside1");
%>

Of course you understand this code will not see the cookie until the page in which is resides is requested after the client side code has set the cookie.

Upvotes: 0

wukong
wukong

Reputation: 2597

you can use Set-Cookie Header rather than javascript

The Set-Cookie response header uses the following format:

Set-Cookie: <name>=<value>[; <name>=<value>]...
[; expires=<date>][; domain=<domain_name>]
[; path=<some_path>][; secure][; httponly]

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318508

ASP runs on the server, JavaScript on the client. So you obviously cannot write to ASP variables from JavaScript.

You need to perform an AJAX call if you want to change something on the server.

Upvotes: 0

Related Questions