如何在asp.net中的javascript中设置会话值 [英] How to set the session value in javascript in asp.net
问题描述
实际上我在我的功能中我想在javascript中设置会话值....我研究了很多关于此的博客。在博客中说我们可以访问但我们无法分配。但在两个博客中,他们说我们也可以分配,但是它在下面不起作用的是他们说我们可以分配的链接
Actually i in my functionality i want to set the session value in javascript....i studied so many blogs about this. in that blogs said we can access but we can not assign. but in two blogs they said we can assign also but it is not working here below is the links where they said we can assign
http://stackoverflow.com/questions/15519454/how-can-i-access-session-variables-and-set-them-in-javascript
http://shekharshetemcts.wordpress.com/2013/11/27/how-to-access-session-variables-using-javascript-in-asp-net/comment-page-1/#comment-294
下面是我的javascriptcode Code.When我在javascript代码中使用上面的链接代码如果条件我收到错误
错误: - 控件集合无法修改,因为控件包含代码块(即)。
Below is my javascriptcode Code.When i am using the above links code in my javascript code if condition i am getting an error
Error:-The Controls collection cannot be modified because the control contains code blocks (i.e. ).
<script type="text/javascript" >
function showorhide(id) {
if (document.getElementById(id).style.display == "none") {
document.getElementById(id).style.display = "block";
var idA = id;
if (idA == "workdiv3") {
//Here i want to Assign the session["Diplay"]="Yes"
}
}
else {
document.getElementById(id).style.display = "none";
var idA = id;
if (idA == "workdiv3") {
//Here i want to Assign the session["Diplay"]="No"
}
}
}
</script>
推荐答案
var id = "10";
'<%Session["x"] = "' + id +'"; %>' ;
alert('<%=Session["x"] %>');
这篇关于如何在asp.net中的javascript中设置会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!