How to Use an EmptyMessage with Password RadTextBoxes

Thread is closed for posting
1 posts, 1 answers
  1. Answer
    Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 02 Dec 2009 Link to this post


    RadControls for ASP .NET AJAX version 2008.1.415 and later
    .NET version 2.0 and later
    Visual Studio version 2005 and later
    Programming language Javascript, C#
    Browser support

    all browsers supported by RadControls for ASP .NET AJAX

    Sometimes you may want to have a textbox' label inside the textbox itself, which is accomplished by the RadTextBox' EmptyMessage. However, this does not work for password texboxes, as they are unable to display non-masked content. The workaround is to have a separate label positioned over the RadTextBox. It can be hidden and shown depending on the RadTextBox value and with the help of the control's API. Here is how to do it:

    <%@ 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 you use Q3 2011 or earlier:
           //myLabel.Attributes.Add("for", RadTextBox1.ClientID + "_text");
           //if you use Q1 2012 or later:       
           myLabel.Attributes.Add("for", RadTextBox1.ClientID);
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    <html xmlns="" > 
    <head runat="server"
    <meta http-equiv="content-type" content="text/html;charset=utf-8" /> 
    <title>RadControls for ASP.NET AJAX</title> 
    <style type="text/css"
        font:12px/22px 'segoe ui',arial,sans-serif; 
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
    <div class="myWrapper"
        <label class="myLabel" id="myLabel" runat="server">Password</label> 
        <telerik:RadTextBox ID="RadTextBox1" runat="server" TextMode="Password" Width="100%"
            <ClientEvents OnFocus="myFocus" OnBlur="myBlur" OnValueChanged="myValueChanged" />  
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
    <script type="text/javascript"
    function myFocus(sender, args) 
        $get("<%= myLabel.ClientID %>").style.display = "none"
    function myBlur(sender, args) 
        if (sender.get_value() == "") 
            $get("<%= myLabel.ClientID %>").style.display = ""
    function myValueChanged(sender, args) 
        if (args.get_newValue() == "") 
            $get("<%= myLabel.ClientID %>").style.display = ""
            $get("<%= myLabel.ClientID %>").style.display = "none"

    Note that positioned elements trigger a layout bug in Internet Explorer, if they are placed inside a scrollable container. In this case you should set a position:relative CSS style to the scrollable container as well.
Back to Top