admin管理员组文章数量:1402824
I'm looking for ways to display some text for the user within an <asp:textbox>
that can help him know what data/format of text he should enter in each textbox. It's looks like this (Sample from Facebook Sign up page) :
My only solution now is to
1- set the default text for the textbox in the aspx
2- Set its color to grey
3- Onclick of the textbox :
1- Change color to black
4- Onchange, if text is empty set the text back to default
This sounds like i'm developing in the 90s, is there an out-of-the-box property for the textbox to do this, or any more intelligent way to do it ?
Happy New Year
I'm looking for ways to display some text for the user within an <asp:textbox>
that can help him know what data/format of text he should enter in each textbox. It's looks like this (Sample from Facebook Sign up page) :
My only solution now is to
1- set the default text for the textbox in the aspx
2- Set its color to grey
3- Onclick of the textbox :
1- Change color to black
4- Onchange, if text is empty set the text back to default
This sounds like i'm developing in the 90s, is there an out-of-the-box property for the textbox to do this, or any more intelligent way to do it ?
Happy New Year
Share Improve this question edited Jan 6, 2015 at 18:05 user3310334 asked Dec 31, 2014 at 16:30 user3340627user3340627 3,1436 gold badges41 silver badges85 bronze badges 03 Answers
Reset to default 5Use the placeholder
attribute,
<input type="text" placeholder="First Name">
Here's a Demonstration.
NOTE:
This attribute only exists in HTML5, and is unsupported in IE < 10, so for IE 7, 8 and 9 see this stackoverflow question, which in turn suggests jQuery Placeholder.
There is also a pure jQuery work-around, explored here.
In html5 there is an attribute that does that for you. It's the placeholder
attribute.
For older browsers, you can polyfill that functionality with placeholder.js; all you have to do is include that script in your page, and it'll work.
<input type="text" placeholder="my super cool placeholder text here" />
Thanks to theonlygusti and J.Wells answer, I got to know what a "placeholder" is. And thanks to this post, I was able to make use of it in my textbox
This answer better serves my purpose as i do not have to change my Textbox into an input field. I used the code below and it worked perfectly :
protected void txtBirthDate_PreRender(object sender, EventArgs e)
{
((TextBox)sender).Attributes.Add("placeholder", "dd/mm/yyyy");
}
Here's the result for my textbox:
EDIT:
From Anant Dabhi's answer here I discovered that I can simply do this :
<asp:TextBox ID="TextBox1" runat="server" placeholder="dd/mm/yyyy" ></asp:TextBox>
本文标签: javascriptDisplay hint for text inside asp39s textboxStack Overflow
版权声明:本文标题:javascript - Display hint for text inside asp's textbox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744328113a2600825.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论