7

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
}
Jaqen H'ghar
  • 16,186
  • 8
  • 49
  • 52
harel486
  • 183
  • 1
  • 1
  • 13
  • This may help: http://stackoverflow.com/questions/20689890/add-html5-placeholder-text-to-a-textbox-net – Pete May 20 '16 at 13:46

1 Answers1

23

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.

Jaqen H'ghar
  • 16,186
  • 8
  • 49
  • 52