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

Simple Client RadInput get_value not working

4 Answers 180 Views
Input
This is a migrated thread and some comments may be shown as answers.
Programmer Nut
Top achievements
Rank 1
Programmer Nut asked on 11 Dec 2008, 11:25 PM
We have used older Rad Controls for years and have a bunch of client-side code that works. We have also gone through RadAJAX client API for hours.........

Can anyone tell us Why doesn't the following code work?????
alert(RadNumericTextBox) simple returns null instead of the object...and we can never get the value.....

A simple example would be greatly appreciated......

_____________________________________________________________________________
<body onload="init();">
    <form id="form1" runat="server">
         <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>   
    <div>
    <script>
        function init()
        {
        var RadNumericTextBox = $find('<%= RadNumericTextBox1.ClientID%>');
        alert(RadNumericTextBox);
        alert(RadNumericTextBox.get_value());
        }
    </script>

        <telerik:RadNumericTextBox ID="RadNumericTextBox1"  runat="server" Value="5">
        </telerik:RadNumericTextBox>

        </div>
    </form>
</body>

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Dec 2008, 12:35 PM
Hi,

Try the above code snippet in the OnLoad client event of the RadNumericTextBox and see if it is working.

ASPX
<telerik:RadNumericTextBox ID="RadNumericTextBox1" Value="5"   ClientEvents-OnLoad="init" runat="server"
        </telerik:RadNumericTextBox> 

JS:
<script type="text/javascript"
function init() 
        { 
        var RadNumericTextBox = $find('<%= RadNumericTextBox1.ClientID%>'); 
        alert(RadNumericTextBox); 
        alert(RadNumericTextBox.get_value()); 
        } 
</script> 
 


Shinu.
0
Programmer Nut
Top achievements
Rank 1
answered on 12 Dec 2008, 04:23 PM
You are on the right path and lead us to our solution...the solution is that you cannot just run the function on the page onLoad event.....Most likely because some javascript (RadControl client side object) initialization from a "ScriptResource.axd" (javascript source) file has not occured yet....If we put a delay in our code all works fine.......I am not saying this is an optimal approach. I am just saying why the original code has problems....

<body onload="init1()">
    <form id="form1" runat="server">
         <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>  
    <div>
    <script>
        function init1()
        {
        setTimeout ( 'init()', 3000 );
        }
        function init()
        {
        var RadNumericTextBox = $find('<%= RadNumericTextBox1.ClientID%>');
        alert(RadNumericTextBox);
        alert(RadNumericTextBox.get_value());
        }
    </script>

        <telerik:RadNumericTextBox ID="RadNumericTextBox1"   runat="server" Value="5">
        </telerik:RadNumericTextBox>


0
Programmer Nut
Top achievements
Rank 1
answered on 12 Dec 2008, 04:44 PM
So I guess the next question is:

Is there an event that is triggered (after body onLoad() ) when the telerik client-side object class is fully available for use.
0
Dimo
Telerik team
answered on 12 Dec 2008, 05:22 PM
Hi Charles,

<body onload="init();">

means "Execute the init() function when the page has been loaded". (i.e. HTML code, script files, etc)

However, the client-side control instances are created afterwards, so it is not suitable to use <body onload=""> to obtain references to these instances.

Please use this:

<script type="text/javascript">

Sys.Application.add_load(methodName);

function methodName()
{
 ......
}

</script>


All the best,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Input
Asked by
Programmer Nut
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Programmer Nut
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or