asp.net - How do I put hint in a asp:textbox -
how put hint/placeholder inside asp:textbox? when hint mean text disappears when user clicks on it. there way achieve same using html / css?
the placeholder
attribute
you're looking placeholder
attribute. use other attribute inside asp.net control:
<asp:textbox id="txtwithhint" placeholder="hint" runat="server"/>
don't bother ide (i.e. visual studio) maybe not knowing attribute. attributes not registered asp.net passed through , rendered is. above code (basically) renders to:
<input type="text" placeholder="hint"/>
using placeholder
in resources
a fine way of applying hint control using resources. way may have localized hints. let's have index.aspx file, app_localresources/index.aspx.resx file contains
<data name="withhint.placeholder"> <value>hint</value> </data>
and control looks like
<asp:textbox id="txtwithhint" meta:resourcekey="withhint" runat="server"/>
the rendered result same 1 in chapter above.
add attribute in code behind
like other attribute can add placeholder
attributecollection
:
txtwithhint.attributes.add("placeholder", "hint");
Comments
Post a Comment