Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder/Example text in textbox for user

What is the step to get example text to show up in an asp.net textbox.

For example, textbox w/ ID = "textboxDate" has [mm/dd/yyyy] inside it for the user to reference.

like image 593
Nick Avatar asked Jun 11 '13 19:06

Nick


4 Answers

I believe you want a placeholder attribute:

<asp:TextBox ID="placeholderTextBox" runat="server" placeholder="mm/dd/yyyy"></asp:TextBox>
like image 93
tymeJV Avatar answered Oct 02 '22 12:10

tymeJV


but placeholder doenst work for many IE browser because placeholder is html5 thing.

try to use modernizr framework. it works for all browsers including all IE

here is a sample code for you.

if(modernizr.input.placeholder) {
   //insert placeholder polyfill script here. 
}
like image 38
Arif YILMAZ Avatar answered Oct 02 '22 13:10

Arif YILMAZ


Visual Studio maybe not knowing the attribute. Attributes which are not registered with ASP.net are passed through and rendered as is.

<asp:TextBox ID="TextBox1" runat="server"  Width="187px" placeholder="mm/dd/yyyy"></asp:TextBox>

So the above code (basically) renders to:

<input type="text" placeholder="mm/dd/yyyy"/>
like image 42
Sohail Qureshi Avatar answered Oct 02 '22 13:10

Sohail Qureshi


You can allways use:

<input ID="placeholderTextBox" type="text" runat="server" placeholder="mm/dd/yyyy" />

and on code behind you can get or set the value using

Dim myValue As String = placeholderTextBox.value or placeholderTextBox.value = "whatsoever"
like image 42
Vicedriver Avatar answered Oct 02 '22 13:10

Vicedriver