Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render title attribute for asp.net textbox

Tags:

html

asp.net

I want to add tooltips to a form on my site. I am using the jQuery tools library. The tooltips show the content of the title attribute of an html input. Is there a way to make the asp.net textbox render out the title attribute in the html input it creates?

like image 828
Elad Lachmi Avatar asked Aug 19 '11 12:08

Elad Lachmi


2 Answers

Since title is a global attribute, according to the W3C HTML language specifications, I would have expected a title property in the System.Web.UI.WebControls.WebControl.

However, Microsoft appears to have chosen a more 'appropriate' name for this property: Tooltip.

If you specify this property:

var label = new Label();
label.ToolTip = "tooltip";
label.Text = "text";
Controls.Add(label);

it will render:

<span title="tooltip">text</span>

which is just what you wanted.

Seeing that Tooltip is a property of the base WebControl, I assume that it will render as a title attribute for all WebControl classes.

like image 85
R. Schreurs Avatar answered Oct 18 '22 05:10

R. Schreurs


You would do something like TextBox1.Attributes.Add("title", "Some title value");

like image 45
CyberDude Avatar answered Oct 18 '22 03:10

CyberDude