Problem with setting the value of RadTextBox client-side

7 posts, 0 answers
  1. Nicklas Johansson
    Nicklas Johansson avatar
    7 posts
    Member since:
    Sep 2008

    Posted 02 Oct 2008 Link to this post

    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!

  2. Dimo
    Admin
    Dimo avatar
    8471 posts

    Posted 02 Oct 2008 Link to this post

    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.
  3. Nicklas Johansson
    Nicklas Johansson avatar
    7 posts
    Member since:
    Sep 2008

    Posted 02 Oct 2008 Link to this post

    The problem is that $find returns null. Maby I'm missing somthing in my code, I just can't figure out what.
  4. Dimo
    Admin
    Dimo avatar
    8471 posts

    Posted 02 Oct 2008 Link to this post

    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.
  5. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 02 Oct 2008 Link to this post

    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).
  6. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 02 Oct 2008 Link to this post

    eep, posted twice!
  7. Nicklas Johansson
    Nicklas Johansson avatar
    7 posts
    Member since:
    Sep 2008

    Posted 03 Oct 2008 Link to this post

    Hi Serrin,

    That worked like a charm. Thanks!

    Pontus
Back to Top