ASP.NET隐藏字段与不可见文本框 [英] ASP.NET hidden field vs. invisible textbox

查看:122
本文介绍了ASP.NET隐藏字段与不可见文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们可以使用标签或文本框之类的其他不可见元素时,在ASP.NET中使用隐藏字段有什么好处?

what are benefits of using a hidden field in ASP.NET when we can use another invisible element such as label or text box?

推荐答案

隐藏字段在页面上生成< input type ="hidden"/> 元素,但该元素无法看到客户端可以获取元素,设置数据并传递给服务器:

The hidden field generate <input type="hidden" /> element on the page, which cannot be seen but the client can get the element, set the data and pass to the server:

document.getElementById('<%= SomeHiddenField.ClientID %>').value = "data_pass_to_server";

回发后,您可以获得值:

after postback you can get the value:

var clientData = SomeHiddenField.Value; // "data_pass_to_server"

如果您使用的是不可见的文本框(< asp:TextBox Visible ="False"/> ),则html文件中不会生成任何元素.

If you're using invisible textbox (<asp:TextBox Visible="False" />), there's no element generated in the html file.

这篇关于ASP.NET隐藏字段与不可见文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆