Update Text Box Label On Focus

4 posts, 0 answers
  1. Anthony
    Anthony avatar
    7 posts
    Member since:
    Oct 2013

    Posted 18 Oct 2013 Link to this post

    I have a RadTextBox (txtFirstName) that I want to update the label text when the text box has focus:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Person.aspx.cs" Inherits="IncidentTracking.Person" %>
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
        <script type="text/javascript">
            function Focus(sender, eventArgs)
            {
                this.txtFirstName.Label = "First Name";
            }
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
        <telerik:RadTextBox ID="txtFirstName" Runat="server" EmptyMessage="First Name" LabelWidth="64px" Resize="None" Width="160px" TabIndex="1">
            <ClientEvents OnFocus="Focus" />
        </telerik:RadTextBox>
    </asp:Content>

    However, when I run this code I get:

    0x800a138f - Microsoft JScript runtime error: Unable to set value of the property 'Label': object is null or undefined
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Oct 2013 Link to this post

    Hi Anthony,

    Please try the following JavaScript to update the RadTextBox value when the RadTextBox have focus.

    JavaScript:

    <script type="text/javascript">
        function Focus(sender, eventArgs) {
            sender.set_value("First Name");
        }
        </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anthony
    Anthony avatar
    7 posts
    Member since:
    Oct 2013

    Posted 28 Oct 2013 Link to this post

    Thank you, Shinu.

    What I'm looking to do is set the value to the Label property when the text box has focus, and when focus is lost, revert back to using the EmptyMessage property.  Any ideas?

     - Anthony
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Oct 2013 Link to this post

    Hi Anthony,

    Please try the following code I tried to set the text  on focus and revert back to EmptyMessage when the focus lost. There is no Label Property for the RadTextBox. set_value() is used to set the text on RadTextBox.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server" EmptyMessage="EmptyMessage">
        <ClientEvents OnFocus="Focus" OnBlur="Blur" />
    </telerik:RadTextBox>

    JavaScript:
    <script type="text/javascript">
        function Focus(sender, args) {
            sender.set_value("First Name");
        }
        function Blur(sender, args) {
            sender.set_value(sender.get_emptyMessage());
        }
    </script>

    Thanks,
    Shinu.
Back to Top