For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > February 2008 > Clear A Textbox/TextArea On-Entry









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Clear A Textbox/TextArea On-Entry
Iain Wilson

2008-02-28, 4:37 am

Hi All

I have a number of textboxes and a textarea on a web form - Using C#.

By default each component contains some text - a hint for the user
entering the data.

What I need to do is clear each component as the user's cursor enters
the component - ie I need an On-Entry event -

Can anyone enlighten me as to how I do this

Many thanks in advance for help offered

Iain
Alexey Smirnov

2008-02-28, 4:37 am

On Feb 28, 9:14=A0am, Iain Wilson <Email.IainWil...@gmail.com> wrote:
> Hi All
>
> I have a number of textboxes and a textarea on a web form - Using C#.
>
> By default each component contains some text - a hint for the user
> entering the data.
>
> What I need to do is clear each component as the user's cursor enters
> the component - ie I need an On-Entry event -
>
> Can anyone enlighten me as to how I do this
>
> Many thanks in advance for help offered
>
> Iain


try this

<asp:TextBox ID=3D"TextBox1" OnClientClick=3D"document.getElementById('<%=3D=

TextBox1.ClientID %>').value=3D'';"
Eliyahu Goldin

2008-02-28, 4:37 am

Don't think there is an OnClientClick event for the textbox.

This markup
<asp:TextBox ID="TextBox1" onfocus="this.value='';" />
will work but will cause the designer to complain.

This code-behind
TextBox1.Attributes["onfocus"]="this.value='';";
will work with no complains

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"Alexey Smirnov" <alexey.smirnov@gmail.com> wrote in message
news:593c1181-4a35-435f-a8b1-fbd82a413da1@u72g2000hsf.googlegroups.com...
On Feb 28, 9:14 am, Iain Wilson <Email.IainWil...@gmail.com> wrote:
> Hi All
>
> I have a number of textboxes and a textarea on a web form - Using C#.
>
> By default each component contains some text - a hint for the user
> entering the data.
>
> What I need to do is clear each component as the user's cursor enters
> the component - ie I need an On-Entry event -
>
> Can anyone enlighten me as to how I do this
>
> Many thanks in advance for help offered
>
> Iain


try this

<asp:TextBox ID="TextBox1" OnClientClick="document.getElementById('<%=
TextBox1.ClientID %>').value='';"


Iain Wilson

2008-02-28, 8:17 pm



The onfocus Event work a treat.
Thanks to all for the help

Iain
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com