how to hide text box character on mouse cliki on textbox

Posted by Shanky11 under ASP.NET on 10/6/2012 | Points: 10 | Views : 4979 | Status : [Member] | Replies : 5
how to hise charactr written in text box on page load as we clik on text box this should be hide and when we clik the cursor outside somewhere else
then it should display the text again




Responses

Posted by: Saratvaddilli on: 10/6/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Before you post in the forum please make sure that your question is understandable .
do you want a text like please enter username on the textbox ...?
if so then use placeholder

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 10/6/2012 [Member] Starter | Points: 25

Up
0
Down
i want like this
plese enter yur name
as we slicl on text box thise disappears and appear again as we clik outside somewehre else

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 10/6/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

post your code here.

Mark as Answer if its helpful to you

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dharanidhar on: 10/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi shanky11,
This can be done using Jquery easily.MAKE IT SIMPLE.
Take a textbox and provide text as "Please enter your name" as below:

<asp:TextBox ID="txt1" runat="server" Text="Please enter your name"></asp:TextBox>
Jquery code
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>

<script type="text/javascript">
$(document).ready(function () {
$("#txt1").focus(function () {
$(this).val("");
});
$("#txt1").blur(function () {
$(this).val("Please enter your name");
});
});
</script>

In the above code.First I have provided the textbox text as "Plese enter your name" to display the text in the textbox on pageload.I have used "focus" event of jquery to set the textbox value(Textbox text) to null when the textbox got focus..And I have used "blur" event to set the textbox value to "please enter your name" so that when we click outside somewhere,the text appears in the textbox.

Thanking You,
Regards.
Dharanidhar

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dharanidhar on: 10/6/2012 [Member] Starter | Points: 25

Up
0
Down
hi shanky11,
You can also do this very easily by using "Asp.net ajax".There is a control called "TextBoxWatermarkExtender" in the asp.net ajax control toolkit.
1.First download ajax control toolkit
2.Add the controls in the toolbox simply by adding .dll file of ajaxcontroltoolkit.u can get all the controls present in the ajaxcontroltoolkit.
3.First Drag and drop "asp:ToolkitScriptManager" from Toolbox and use "asp:TextBoxWatermarkExtender" control which is suitable for your scenario.
The code is as follows:
 <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">

</asp:ToolkitScriptManager>
<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
<asp:TextBoxWatermarkExtender ID="textext" runat="server" TargetControlID="txt1" WatermarkText="please enter your name"></asp:TextBoxWatermarkExtender>

Here I have taken one textbox and TextBoxWatermarkExtender control.In this ajax control i have specified targetcontrolID as textbox id("txt1") and WatermarkText as "Please enter your firstname" as this text displays in the textbox when pageloaded and also when the textbox looses focus(i.e..,when we clck on somewhere else).And the text disappers automatically when the textbox got focus.

Thanking You,
Regards,
Dharanidhar

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response