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

show empty message on page load

7 Answers 226 Views
Input
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 06 Mar 2009, 06:58 PM
I have a search text box on my page.
On the first page load I want to display the textbox with a message like "enter name here"
Once the user starts typing int he textbox i want the message to go away and just show the text that the user typed.

I tried setting EmptyMessage but it does not show.

7 Answers, 1 is accepted

Sort by
0
Steve Y
Top achievements
Rank 2
answered on 08 Mar 2009, 10:40 PM
EmptyMessage should be the way to go for the functionality you're describing. It works fine for me with both a RadNumericTextBox or an asp:TextBox with RadInputManager controlling it. What are you using? Can you post your control declaration?

regards, steve
0
newbie
Top achievements
Rank 1
answered on 09 Mar 2009, 06:27 AM
this is my control declaration:

<

telerik:RadTextBox ID="RadTextBoxName" runat="server" TabIndex="4" onfocus="movetoend()"

 

 

Width="175px" ForeColor="#898a8c" Font-Names="Tahoma" Font-Size="12pt" OnTextChanged="RadTextBoxName_OnTextChanged"

 

 

Height="16px" EmptyMessage="Name">

 

 

</telerik:RadTextBox>

 

0
Steve Y
Top achievements
Rank 2
answered on 09 Mar 2009, 01:47 PM
I just took your declaration, put it onto one of my pages, and it worked fine for me. Does the control have focus on initial load?.If so, the text will not be visible as it disappears with focus and will appear if focus is not on the control and the control is empty. This is so that when you click in a textbox the box will be empty for your user data input.

One other non-related thing, you may not need your onfocus declaration as the control has one built-in. Try changing onfocus="movetoend()" to be:

<telerik:RadTextBox ID="RadTextBoxName" runat="server" TabIndex="4" SelectionOnFocus="CaretToEnd" 
        Width="175px" ForeColor="#898a8c" Font-Names="Tahoma" Font-Size="12pt" Height="16px" EmptyMessage="Name"
    </telerik:RadTextBox> 

0
newbie
Top achievements
Rank 1
answered on 09 Mar 2009, 05:53 PM
thanks for pointing that out.

yes the control does have focus on initial load.
But I still need to display the initial text somehow and want it to disaapear as soon as the user starts typing in.

is that possible to achieve?
0
Steve Y
Top achievements
Rank 2
answered on 09 Mar 2009, 07:56 PM
The simple way of doing it is to not have the input field focused on initial load. Then your emptymessage will be displayed.

If you need the focus to be in the input control and have the empty message displayed until the user starts typing, then I don't know of a easy way of doing that (i.e. standard within the control declaration/ without the use of javascript or modifying the css). Perhaps someone else can jump in with an idea here...

Steve
0
Dimo
Telerik team
answered on 10 Mar 2009, 06:45 AM
Hello Anumeha,

Having an empty message visible inside a focused textbox is not a very good idea, because this means that the textbox will hold a value, which is not real. You will have to take care of removing and adding the fake value and make sure that it is not treated like a real value. That's why I recommend avoiding such a scenario. Like Steve suggested, you can use a regular EmptyMessage, no matter whether you focus the textbox initially or not. Another way to tell the user what to type in the textbox is to use the RadTextBox' Label.

If you still insist on implementing the desired behavior, here is a hint:

<%@ Page Language="C#" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<script runat="server"
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (RadTextBox1.Text == String.Empty) 
        { 
            RadTextBox1.Text = "type here"
        } 
        RadTextBox1.Focus(); 
    } 
     
</script> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>RadControls for ASP.NET AJAX</title> 
</head> 
<body> 
<form id="form1" runat="server"
<asp:ScriptManager ID="ScriptManager1" runat="server" /> 
 
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text=""
    <ClientEvents OnKeyPress="KeyPress" /> 
</telerik:RadTextBox> 
 
<asp:Button ID="Button1" runat="server" Text="PostBack" /> 
 
<script type="text/javascript"
 
function KeyPress(sender, args) 
    if (sender.get_value() == "type here") 
    { 
        EmptyValueFlag = true
        args.set_cancel(true); 
        sender.set_value(args.get_keyCharacter()); 
    }    
 
</script> 
 
</form> 
</body> 
</html> 


Sincerely yours,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
newbie
Top achievements
Rank 1
answered on 12 Mar 2009, 08:21 PM
thanks Dimo,

I guess for now I'll just stick to showing the empty message and not doing an initial focus.
Tags
Input
Asked by
newbie
Top achievements
Rank 1
Answers by
Steve Y
Top achievements
Rank 2
newbie
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or