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

set value of RadNumericTextBox in repeater with javascript

2 Answers 285 Views
Input
This is a migrated thread and some comments may be shown as answers.
Luka
Top achievements
Rank 1
Luka asked on 24 May 2012, 12:45 PM
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 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 28 May 2012, 01:34 PM
Hello Luka,

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

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

Javascript:
function TextChange(sender, args) 
{
    var numTextBox = $find(sender.get_id().replace("RadTextBox1","RadNumericTextBox1"));
    numTextBox.set_value(1);
}

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.
0
Luka
Top achievements
Rank 1
answered on 28 May 2012, 02:59 PM
What a brilliant solution. Simple, elegant and no dom traversing!

Thank you, it worked perfectly!
Tags
Input
Asked by
Luka
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Luka
Top achievements
Rank 1
Share this question
or