简体   繁体   English

在C#中获取属性的值

[英]Getting the value of an attribute in C#

I have several textboxes that dynamically add placeholder text and later on in my code I wish to retrieve that text from each textbox. 我有几个文本框可动态添加占位符文本,稍后在我的代码中,我希望从每个文本框中检索该文本。 Below is an example of a text box: 下面是一个文本框的示例:

<asp:TextBox ID="tbFirstName" runat="server" CssClass="form-control" placeholder=""></asp:TextBox>

Later on in the code I wish to have something like this (psudocode): 稍后在代码中,我希望具有以下内容(伪代码):

string firstname = tbFirstname.placerholderText;

Any suggestions? 有什么建议么?

You can refer it by the attribute name 您可以通过属性名称来引用它

string firstname = tbFirstname.Attributes["placeholder"];

or set the placeholder value 或设置占位符值

tbFirstName.Attributes["placeholder"]="Some text";

That should work fine for HTML Server controls as well. 对于HTML Server控件也应该可以正常工作。

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

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