asp:TextBox通过.NET代码更改占位符

时间:2016-05-20 13:43:39

标签: html asp.net .net

是否可以通过ASP.NET代码更改文本框placeholder?如果是这样,怎么样?

标记:

<asp:TextBox ID="TXTPassR" runat="server" CssClass="form-control" 
    placeholder="Enter password" TextMode="Password"></asp:Textbox>

代码背后:

if (Something)
{
   //Change placeholder
}

1 个答案:

答案 0 :(得分:11)

使用Attributes.Add()

if (Something)
{
    TXTPassR.Attributes.Add("placeholder", "Some Text");
}
  

AttributeCollection.Add Method(String,String):将属性添加到服务器控件的AttributeCollection对象。