[英]How can i Get a Another Form Session Value in Java Script File Using ASP.Net?
am having Sample.aspx and sample.js both are in different directory. 我的Sample.aspx和sample.js都位于不同的目录中。
how can i get the Sample.aspx page session values in sample.js file ? 我如何在sample.js文件中获取Sample.aspx页面会话值?
i cant get the value for the following types 我无法获得以下类型的值
function session() {
alert('<%=Session.getAttribute("hdn_CheckedData")%>');
alert(document.getElementbyId("hdn_CheckedData").value);
alert('<%=Session["CheckedData"]%>');
alert('<%=Session("CheckedData")%>');
alert('<%=Session["CheckedData"].ToString()%>');
alert('<%=Session("CheckedData").ToString()%>');
};
CheckedData - is the session CheckedData-是会话
hdn_CheckedData - is the hiddenfield hdn_CheckedData-是hiddenfield
i tried both of it. 我都尝试了。
is it possible then help me pls..... 有没有可能然后帮助我.....
Hiddenfiled, session, viewstate or anything............ 隐藏文件,会话,视图状态或其他任何内容.........
One simple solution is to declare the session variables just before the load of your javascript file and inside the aspx page. 一种简单的解决方案是在加载javascript文件之前并在aspx页面内声明会话变量。 Eg on sample.aspx you have
例如在sample.aspx上
<script>
var sessionCheckData = "<%=session["CheckedData"].ToString()%>";
</script>
<script type="text/javascript" src="sample.js"></script>
and on sample.js
you have 在
sample.js
上
function session() {
alert(sessionCheckData);
};
Similar answer: How to get asp.net client id at external javascript file 类似的答案: 如何在外部javascript文件中获取asp.net客户端ID
You can save the session data to a hidden field on your page. 您可以将会话数据保存到页面上的隐藏字段中。 After that you have direct access to that field in you js file.
之后,您可以直接访问js文件中的该字段。
Or you can declare a session variable as Aristos has proposed. 或者,您可以按照Aristos的建议声明会话变量。 That would more straightforward actually.
实际上,那将更加简单。
You have to assign session values to hiddenfield 您必须将会话值分配给hiddenfield
after that you can use that values 之后,您可以使用该值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.