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

OnBlur, RadNumericTextBox in repeater

2 Answers 119 Views
Input
This is a migrated thread and some comments may be shown as answers.
Jennifer
Top achievements
Rank 1
Jennifer asked on 24 Sep 2010, 07:19 PM
Hi,

I have a repeater and I want to use 2 radnumerictextboxes in the template. Then I need to call a javascript function on one of them that will copy its value to the other control onblur

<telerik:RadNumericTextBox runat="server" ID="txtRisk" NumberFormat-DecimalDigits="2" Type="Number"  Width="65" CssClass="BetslipTextBox" ShowSpinButtons="true" ButtonsPosition="Right" IncrementSettings-InterceptArrowKeys="true" IncrementSettings-Step="1" MinValue="5" MaxValue="9999" ></telerik:RadNumericTextBox>

<telerik:RadNumericTextBox runat="server" ID="txtWin" NumberFormat-DecimalDigits="2" Type="Number"  Width="65" CssClass="BetslipTextBox" ShowSpinButtons="true" ButtonsPosition="Right" IncrementSettings-InterceptArrowKeys="true" IncrementSettings-Step="1" MinValue="5" MaxValue="9999" ></telerik:RadNumericTextBox>

I did this in code-behind:

RadNumericTextBox w = (RadNumericTextBox)e.Item.FindControl("txtWin");
RadNumericTextBox r = (RadNumericTextBox)e.Item.FindControl("txtRisk");
w.Attributes.Add("onblur", "return CalculateRisk(" + w.ClientID + "," + r.ClientID + ");");

in the javascript:

This shows me the value correctly:
 alert(document.getElementById(win.id).value);
which is:
ctl00_ContentPlaceHolder1_rptName_ctl01_txtWin

but I can't set it

when I view source it shows that it added a "_text" to the end of the id so it really is:

ctl00_ContentPlaceHolder1_rptName_ctl01_txtWin_text


This does set it (when I hard code it):
document.getElementById('ctl00_ContentPlaceHolder1_rptStraight_ctl01_txtWin_text').value = "50";

What is the right way to do this?  The above code does work for a regular asp:textBox but I want to use yours!

I also tried  <ClientEvents OnBlur="TestOnBlur /> and was able to get the sender but how do I access the other controls if I cant pass them?

Thanks

2 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 24 Sep 2010, 08:41 PM
Hello Jennifer,

Using the RadNumericTextBox's OnBlur event, try this:

function OnBlur(sender, args){
   $find(sender.get_id().replace("txtRisk", "txtWin")).set_value(sender.get_value());
}

What it does is try to find the related txtWin control of txtRisk and sets the value to one set in txtRisk. Since both controls have the same front portion of their id the same, I just replace the control-specific portion with the other. Also, I'm using the $find method to find the control, since that is how you work with Telerik controls and modify their values.

I hope that helps.
0
Jennifer
Top achievements
Rank 1
answered on 24 Sep 2010, 09:32 PM
Perfect. I never thought of that. Thanks a lot!
Tags
Input
Asked by
Jennifer
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Jennifer
Top achievements
Rank 1
Share this question
or