简体   繁体   English

从其他网页访问“隐藏字段”值

[英]Accessing Hidden Field value from a different webpage

I have stored a string value in a hidden field of a page. 我已将字符串值存储在页面的隐藏字段中。 How to access it from a different webpage? 如何从其他网页访问它?

You have two options. 您有两个选择。

a. 一种。 Putting that string value in a Session. 将该字符串值放入会话中。

  string value="value"; Session["myValue"] = value; 

b. b。 Transmitting that value in the url. 在网址中传输该值。

 string value="value";
 Response.Redirect("./Mypage.aspx?value="+value);

On the page that contains the hidden value, you could post that form to the other page and get the value from this.Request.Form["hidden-field"]. 在包含隐藏值的页面上,您可以将该表单发布到另一页上,并从this.Request.Form [“ hidden-field”]中获取值。

Is that the sort of answer you are looking for? 您是否正在寻找这种答案? Maybe more details would help. 也许更多细节会有所帮助。

Good luck! 祝好运!

If you don't mind using jQuery, and as long as the pages are on the same domain, then you can do it with the .load() method. 如果您不介意使用jQuery,并且只要页面位于同一域中,则可以使用.load()方法来实现。 This method basically does a GET request to the page 此方法基本上对页面执行GET请求

Page with hidden field 带有隐藏字段的页面

<div id="hiddenValue">Value</div>

Page you're calling from 您正在呼叫的页面

$('#newDiv').load('path/to/page.aspx #hiddenValue');

additional notes: 补充笔记:

  • Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy ; 由于浏览器安全性的限制,大多数“ Ajax”请求都受相同的原始策略约束; the request can not successfully retrieve data from a different domain, subdomain, or protocol. 该请求无法成功从其他域,子域或协议检索数据。

If they are on different domains then your only other options are: 如果它们在不同的域中,那么您唯一的其他选择是:

  • Query Strings 查询字串

  • Sessions 届会

references: 参考资料:

You can also use cookies to transfer the value across pages. 您也可以使用cookie在页面之间转移价值。 May be you would want to read this piece of article to know more about the state management. 您可能想阅读这篇文章,以了解有关状态管理的更多信息。 Do read it. 读吧。 Will definitely gonna help you. 一定会帮助你的。 You can decide what you want to use after reading this. 阅读此书后,您可以决定要使用什么。

Hope it helps you. 希望对您有帮助。 http://www.codeproject.com/KB/vista/ASPNet_State_Management.aspx http://www.codeproject.com/KB/vista/ASPNet_State_Management.aspx

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM