Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp:TextBox change placeholder via .NET code behind

Tags:

html

.net

asp.net

Is it possible to change textbox placeholder via ASP.NET code behind? If so, how?

Markup:

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

Code behind:

if (Something)
{
   //Change placeholder
}
like image 598
harel486 Avatar asked May 20 '16 13:05

harel486


1 Answers

Use Attributes.Add():

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

AttributeCollection.Add Method (String, String): Adds an attribute to a server control's AttributeCollection object.

like image 61
Jaqen H'ghar Avatar answered Nov 06 '22 06:11

Jaqen H'ghar