Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
in .Net Framework by 5 5 8

In HTML, I can add a placeholder attribute to input filed to show a hint to a user about the content of this input filed. but I am wondering if it's possible to add a hint text inside ASP.NET TextBox control?

placeholder in ASP TextBox Control

1 Answer

1 like 0 dislike
by 155 174 351
selected by
Best answer

Adding placeholder for Textbox in ASP.NET

To add a hint inside your TextBox in ASP.Net, you can easily use the "placeholder " keyword attribute as below

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

Adding placeholder for Textbox at Code-Behind in ASP.NET

In code-behind, you can set a placeholder for a TextBox using C# as the following:

Method 1

txt_Name.Attributes.Add("placeholder", "your hint");

Method 2

txt_Name.Attributes["placeholder"] =  "your hint";
If you don’t ask, the answer is always NO!