How to use asp variable in JavaScript?
I have stored text box value in JavaScr开发者_JAVA百科ipt 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?
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]
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")
...
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.
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.
精彩评论