what is the best and most simplest way to create tooltip text for textboxes
4 Answers
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.
1 Comment
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 })
Comments
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.
