Reputation: 12304
what is the best and most simplest way to create tooltip text for textboxes
Upvotes: 6
Views: 19473
Reputation: 3326
Just use the title tag :
<input type="text" title="Hello I'm the tool-tip"/>
Mvc way :
@Html.TextBoxFor(t => t.NameOfCustomer, new{ title= "Hello I'm the tool-tip" })
It's not fully customizable as is, but it does not require extra javascript nor a framework.
Upvotes: 3
Reputation: 125538
With JavaScript and probably with a framework like jQuery that fits very well with ASP.NET MVC. Using the framework means that someone's alread done the hard work and written a plugin for it!
There is of course the title
attribute on text inputs that shows as a popup tip in some browsers.
Upvotes: 4
Reputation: 3503
I found this to be the simplest and easy to maintain approach:
Create description using data annotation for the property of your model Example:
[Display(Name="MyTextBox", Description = "Title for your entry")]
public string MyTextBox{ get; set; }
Then in your view access the description above using:
@Html.TextBoxFor(model => model.MyTextBox, new { title = ModelMetadata.FromLambdaExpression(model => model.MyTextBox, ViewData ).Description })
Upvotes: 4
Reputation: 419
Use the data annotations on your model to put the tooltip in the Description property of the DisplayAttribute.
Then write your own Html Helper function that puts the Description property into the title attribute of the TextBox input field. You can call the helper TextBoxWithTooltipFor
In your view definition you can then replace the call to @(Html.TextBoxFor(...)) with the call to @(Html.TextBoxWithTooltipFor(...))
Here is the code that is tested and works.
Upvotes: 0