C#获取属性值

Getting the value of an attribute in C#

我有几个动态添加占位符文本的文本框,稍后在我的代码中我希望从每个文本框中检索该文本。下面是一个文本框的例子:

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

稍后在代码中我希望有这样的东西(伪代码):

string firstname = tbFirstname.placerholderText;

有什么建议吗?

可以通过属性名引用

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

或设置占位符值

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

这对于 HTML 服务器控件应该也能正常工作。