set value of RadNumericTextBox in repeater with javascript

3 posts, 0 answers
  1. Luka
    Luka avatar
    2 posts
    Member since:
    May 2012

    Posted 24 May 2012 Link to this post

    I have to set the value of a RadNumerictextBox. The first problem is that it is in a repeater so I cannot get the object by id. And the second problem is, the event is not fired by the NumericTextBox, but by another control in the repeater (in the same line), so I cannot use the sender argument of the function.

    I am able to get the parent of the first control (the one that fires the event), and then look through its children and find the many html elements the RadNumerictextBox renders to. But these are html elements and don't expose the client api.

    Specifically it renders into a span containing a span and an input. I had assumed that the first span represents the value displayed, and the input the actual value, the one sent back to the server.
    I tried to cheat and access these two elements through their classes and set their values, but it doesn't work. The new value shows up for a second and then resets.

    tldr: I need a way to access the NumericTextBox and set its value, in a javascript event fired by another control in the same line in a repeater.

    If I had not explained my problem clearly enough please say so and I shall attempt to provide you with more details.
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 28 May 2012 Link to this post

    Hello Luka,

    If the control raising the event is another server control, then you could do something like this:

    <asp:Repeater ID="Repeater1" runat="server">
            <telerik:RadTextBox ID="RadTextBox1" runat="server">
                <ClientEvents OnClientTextChange="TextChange" />
            <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" />

    function TextChange(sender, args) 
        var numTextBox = $find(sender.get_id().replace("RadTextBox1","RadNumericTextBox1"));

    In this case it's RadTextBox, so I use the get_id() method to pull out the id of the control. Now because both controls would share the same naming convention, I can replace the RadTextBox1 part of the id with RadNumericTextBox1 and produce the id of the RadNumericTextBox.

    I hope that helps.
  3. Luka
    Luka avatar
    2 posts
    Member since:
    May 2012

    Posted 28 May 2012 Link to this post

    What a brilliant solution. Simple, elegant and no dom traversing!

    Thank you, it worked perfectly!
Back to Top