This is a migrated thread and some comments may be shown as answers.

How to clear the content in a RadTextbox when OnFocus

3 Answers 371 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ervin
Top achievements
Rank 1
ervin asked on 07 Feb 2012, 04:12 PM
Hello,
I am trying to clear the content of a RadTextBox when user focuses on the textbox. I tried several ways but could not clear the content using javascript.

"LASTNAME" is written into a RadTextbox and when user focuses to this RadTextbox, "LASTNAME" should be cleared so that the user can write his/her name...

I tried to clear it using javascript;

<script type="text/javascript">

function clear()
{
$find("<%=RadTextBox1.ClientID %>").clear();
}
</script>

But it did not work. It reads the clear method but does nothing. So how can I clear the content, any ideas?

Thanks,
Ervin

3 Answers, 1 is accepted

Sort by
0
Accepted
Casey
Top achievements
Rank 1
answered on 07 Feb 2012, 08:21 PM
Hi Ervin,

Have you tried setting the EmptyMessage property of the RadTextBox to "LASTNAME" instead of the Text property? This should automatically clear when the user focuses to the RadTextBox.

I hope this helps!
Casey
0
Shinu
Top achievements
Rank 2
answered on 08 Feb 2012, 05:08 AM
Hello Ervin,

Here is the code which worked as expected in my end.
JS:
<script type="text/javascript">
 function OnFocus(sender, args)
{
    sender.clear();
 }
</script>

-Shinu.
0
ervin
Top achievements
Rank 1
answered on 08 Feb 2012, 03:59 PM
I tried Casey's method and it worked! EmptyMessage property is good to go!

Thank you Casey and Shinu for your replies!
Ervin 
 
Tags
Grid
Asked by
ervin
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
ervin
Top achievements
Rank 1
Share this question
or