C # - how to set text in textbox to show tooltip when textbox is empty?

I am using the <asp:TextBox> not HTML text box and I want to display the tooltip text.

Is there any way to achieve this?

I tried to make the static text and color it gray, but not get how to make it empty when the cursor starts focusing on this text box.

+6
source share
7 answers
 <asp:TextBox ID="TextBox1" runat="server" placeholder="Hint Text"></asp:TextBox> 
+8
source
+6
source

You can give the code as shown below.

 textBox.Attributes.Add("onfocus", "clearText(this,'" + defaultText + "')"); 

Also refer to this to find out more.

+3
source

You can use the "placeholder" properties for the text field.

Example

 <asp:TextBox ID="TextBox1" runat="server" Width="233px" placeholder="Search"></asp:TextBox> 
+3
source

You can use the HTML5 placeholder attribute for this. The disadvantage is that it is only supported by some browsers. Fortunately, you have a jQuery Placeholder for salvation. This plugin makes placeholder behavior available to unsupported browsers.

Check it out here jQuery Placeholder

+1
source
0
source

just add the placeholder="HintText" property to the asp text box

-1
source

Source: https://habr.com/ru/post/899273/


All Articles