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

Problem with setting the value of RadTextBox client-side

6 Answers 362 Views
Input
This is a migrated thread and some comments may be shown as answers.
Nicklas Johansson
Top achievements
Rank 1
Nicklas Johansson asked on 02 Oct 2008, 01:27 PM
I'v been beating my head with this the whole day and cant figure out why it doesn't work...

I'm trying to set the value of a RadTextBox with javascript and according to the documentation you should do that with the method set_value. However my browser keeps telling me that this method does not exist.

here is my code:

<%

@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="GateKeeper.Test" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server">

<title></title>

<telerik:RadCodeBlock runat="server">

<script>

function Configuration() {

var oInput = $get('<%= TestTextBox.ClientID%>');

oInput.set_value(

'Test');

}

</script>

</telerik:RadCodeBlock>

</

head>

<

body onload="Configuration()">

<form runat="server" id="form1">

<telerik:RadScriptManager runat="server"></telerik:RadScriptManager>

<telerik:RadTextBox ID="TestTextBox" runat="server"></telerik:RadTextBox>

</form>

</

body>

</

html>

Please help!

6 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 02 Oct 2008, 01:51 PM
Hi Nicklas Johansson,

You should use $find instead of $get.

$get returns a simple HTML element, the same as document.getElementById("...")

$find returns the client-side instance of the control


Sincerely yours,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nicklas Johansson
Top achievements
Rank 1
answered on 02 Oct 2008, 03:04 PM
The problem is that $find returns null. Maby I'm missing somthing in my code, I just can't figure out what.
0
Dimo
Telerik team
answered on 02 Oct 2008, 03:21 PM
Hello Nicklas,

You are right, at the time the Configuration() function is executed, the textbox control has not been instantiated yet. That's why you need to remove the onload attribute from the <body> tag and use a different approach:

<telerik:RadTextBox ID="TestTextBox" runat="server"></telerik:RadTextBox>  
 
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
<script type="text/javascript"
 
Sys.Application.add_load(Configuration) 
 
function Configuration() { 
    var oInput = $find('<%= TestTextBox.ClientID%>'); 
    oInput.set_value('Test'); 
 
</script> 
</telerik:RadCodeBlock>  
 



Greetings,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Serrin
Top achievements
Rank 1
answered on 02 Oct 2008, 03:29 PM
Hey Nicklas,

Have you tried moving the command (and using $find) to textbox clientevents like below:

<telerik:RadCodeBlock runat="server">   
 
<script type="text/javascript">   
 
function Configuration()   
{   
    var oInput = $find('<%= TestTextBox.ClientID %>');   
 
    oInput.set_value('Test');   
}  
 
</script>   
 
</telerik:RadCodeBlock>   
 
</head>   
 
<body>   
 
<form runat="server" id="form2">   
 
<telerik:RadScriptManager runat="server"></telerik:RadScriptManager>   
 
<telerik:RadTextBox ID="TestTextBox" runat="server">  
<ClientEvents OnLoad="Configuration" /> 
</telerik:RadTextBox>   
 
</form>   
 
</body>  

Testing that and it works everytime... would that solution work for you?  I think the problem is that you were firing it in the Body onload tag, googling that shows that a number of people have trouble with it firing in IE7 (which I am using).
0
Serrin
Top achievements
Rank 1
answered on 02 Oct 2008, 03:29 PM
eep, posted twice!
0
Nicklas Johansson
Top achievements
Rank 1
answered on 03 Oct 2008, 07:57 AM
Hi Serrin,

That worked like a charm. Thanks!

Pontus
Tags
Input
Asked by
Nicklas Johansson
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Nicklas Johansson
Top achievements
Rank 1
Serrin
Top achievements
Rank 1
Share this question
or