1

Is there any way in MVC to specify "Empty Text" for text fields?

Empty Text is normally a property give to a textbox to display when text is empty, and is cleared out OnClick.

For example: have the text box say "Enter here..." and then onFocus that text would clear and allow you to type in the entry, however if text is empty, "Enter here..." would display again.

I'm trying to find out if there's any ways to get this out of the box w/o any additional coding, as this feature is widely supported by 3rd Party controls (ie: Telerik's AJAX Controls) does anyone know if MS made any provisions to offer anything similar?

Thanks.

3 Answers 3

4

You could use HTML5 placeholder attribute:

@Html.TextBoxFor(x => x.SomeProperty, new { placeholder = "some default text" })

And if you need to support older browsers you could always achieve the same effect with javascript. For example there are existing jQuery plugins such as jQuery.placeholder.

Sign up to request clarification or add additional context in comments.

1 Comment

do you have to use HTML5 rending in the project?
1

Use placeholder attribute in HTML 5

Comments

0

There's no such thing as what you are referring to in HTML, at least not called that. 3rd party controls have implemented this functionality themselves.

There is, in HTML 5, a property called a placeholder, but this won't appear in non-html5 compliant browsers (IE8, IE7, older versions of FF, etc..)

The only way to do this cross browser is to use javascript to implement the functionality.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.