2016-05-20 29 views
1

是否有可能通過ASP.NET代碼後面更改文本框placeholder?如果是這樣,怎麼樣?asp:文本框通過後面的.NET代碼更改佔位符

標記:

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

代碼後面:

if (Something) 
{ 
    //Change placeholder 
} 
+0

這可能有助於:http://stackoverflow.com/questions/20689890/add-html5-placeholder-text-to-a-textbox-net – Pete

回答

2

使用Attributes.Add()

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

AttributeCollection.Add方法(字符串,字符串):添加的屬性的服務器控件的AttributeCollection對象。

+0

工程。謝謝 :) – harel486