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

Update Text Box Label On Focus

3 Answers 70 Views
Input
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 18 Oct 2013, 04:35 PM
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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 21 Oct 2013, 03:40 AM
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.
0
Anthony
Top achievements
Rank 1
answered on 28 Oct 2013, 11:29 PM
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
0
Shinu
Top achievements
Rank 1
answered on 29 Oct 2013, 05:27 AM
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.
Tags
Input
Asked by
Anthony
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Anthony
Top achievements
Rank 1
Share this question
or