RadTextBox Attribute

3 posts, 2 answers
  1. Jeroen Eikmans
    Jeroen Eikmans avatar
    50 posts
    Member since:
    May 2009

    Posted 25 Mar 2010 Link to this post

    Hi,

    I have a RadTextBox on my page.
    Using radTextBox.Attributes.Add("Key", "Value") I add some value i need to the control.

    I've been looking for a way where i can get that value in the ClientEvent OnTextChanged.
    The sender in the OnTextChanged-event (which is the RadTextBox i believe) doesn't have a method like get_attribute.

    Is there some other way to access this attribute client-side?

    Kind regards,
    Roel
  2. Answer
    Dimo
    Admin
    Dimo avatar
    8483 posts

    Posted 25 Mar 2010 Link to this post

    Hi Roel,

    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)
        {
            RadTextBox1.Attributes.Add("mykey", "myvalue");
        }
         
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     
    <head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>RadControls</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
     
    <telerik:RadTextBox ID="RadTextBox1" runat="server">
        <ClientEvents OnValueChanged="MyValueChanged" />
    </telerik:RadTextBox>
     
    <script type="text/javascript">
     
    function MyValueChanged(sender, args)
    {
        alert(sender._textBoxElement.getAttribute("mykey"));
    }
     
    </script>
     
    </form>
    </body>
    </html>


    Sincerely yours,
    Dimo
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Mar 2010 Link to this post

    Hello,

    I tried following code in order to get the attribute that we set from from code behind.

    C#:
     
    RadTextBox1.Attributes.Add("key","value"); 

    JavaScript:
     
        function OnValueChanged(sender, args) { 
            alert(sender._textBoxElement.getAttribute("key"));       
        } 

    Try this and see whether it is working fine for you.

    Regards,
    Princy.
Back to Top