Reputation: 10567
i have the following Textbox in an asp.net page.
<asp:TextBox ID="TtxtMessage" Text="Write Here" ForeColor="Control" runat="server" Height="300px" TextMode="MultiLine" Width="274px"></asp:TextBox>
The default text in the Text box will be write here
. If the user clicks that i want to clear the text and this should happen only on the first click.For the subsequent clicks the content entered by the user should remain the same. How to do this using Javascript or Code Behind ?
Upvotes: 0
Views: 2053
Reputation: 65941
A placeholder would be a good answer for this (see Add HTML5 placeholder text to a textbox .net).
However using jquery (note I'm not sure if asp.net still mangles the controls ID's in the rendered html) something like this may work:
<script>
$(document).ready(function() {
var firstClickOccurred = false;
$("#TtxtMessage").focus(function() {
if(!firstClickOccurred) {
$(this).val('');
firstClickOccurred = true;
}
});
});
</script>
Upvotes: 2
Reputation: 1926
You can use the placeholder property like this
<asp:TextBox ID="TtxtMessage" placeholder="Write Here" ForeColor="Control" runat="server" Height="300px" TextMode="MultiLine" Width="274px"></asp:TextBox>
Upvotes: 2