简体   繁体   English

在ASP.NET代码后面访问文档?

[英]Access document in ASP.NET code behind?

If I do this in javascript 如果我在javascript中执行此操作

document.attributes["Test"] ='1'; 

How can I access that in ASP.NET server side code? 如何在ASP.NET服务器端代码中访问它?

I looked for Attributes on this.Page , but it wasn't there. 我在this.Page上查找了Attributes ,但是它不存在。

Document attributes aren't posted back to the server. 文档属性不会回发到服务器。

What I do is add a hidden server control, then update that hidden control in javascript. 我要做的是添加一个隐藏的服务器控件,然后在javascript中更新该隐藏的控件。 That will be posted back to the server, and can be accessed. 那将被发回到服务器,并且可以被访问。

This would be the server control. 这将是服务器控件。 (note the clientidmode attribute, this is so that I can easily access this control in javascript) (请注意clientidmode属性,以便我可以轻松地在javascript中访问此控件)

<asp:HiddenField runat="server" ClientIDMode="Static" ID="hdnTest"/>

Then in javascript 然后在JavaScript

document.getElementById("hdnTest").value = '1';

And to access it in the codebehind 并在后面的代码中访问它

hdnTest.Value

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

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