简体   繁体   English

如何使用ASP.Net在Java脚本文件中获取另一个Form会话值?

[英]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. 实际上,那将更加简单。

I would write a generic handler and use JSONP to pass any data to external Javascript. 我将编写一个通用处理程序,并使用JSONP将任何数据传递到外部Javascript。

Please take a look at here , here and here . 请在这里这里这里看看。

Since it is not cross domain, JSON should also work. 由于它不是跨域的,因此JSON也应该起作用。

You have to assign session values to hiddenfield 您必须将会话值分配给hiddenfield

after that you can use that values 之后,您可以使用该值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JavaScript从ASP.Net MVC中的表单获取“验证消息”的值? - How can I get the value of Validation Message from form in ASP.Net MVC, using javascript? 如何在ASP.NET MVC的外部js文件中使用jQuery获取会话变量的值 - How to get value of session variable using jQuery in external js file in ASP.NET MVC 获取会话值 - ASP.NET Web 处理程序文件 - get session value - ASP.NET Web Handler file 我可以将.aspx页中的Java脚本接收到的值传递给asp.net中其对应的.cs文件吗? - Can i pass value received by the java-script in .aspx page to its corresponding .cs file in asp.net? 如何在ASP.NET MVC中获取ViewBag值? - How can I get ViewBag value in ASP.NET MVC ? 当我重定向到ASP.NET MVC中的另一个网站时如何保持会话 - How can I persist a session when I redirect to another website in ASP.NET MVC 如何获取DropDownList选定的值,并将其发送到ASP.NET MVC 4中的控制器并使用JavaScript? - How can I get a DropDownList selected value and send it to the controller in ASP.NET MVC 4 and using JavaScript? 如何将 ASP.NET 向导中的表单数据添加到会话数组对象中? - How can I add form data from ASP.NET wizard into a session array object? 如何在ASP.NET 5 MVC6中的布局文件中获取会话值 - How to get a session value in layout file in ASP.NET 5 MVC6 如何在asp.net MVC中的外部JavaScript文件中获取会话值,tempdata? - How to get the session value, tempdata in external JavaScript file in asp.net MVC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM