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

Troubles with Ajax $get

4 Answers 88 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
hk proj
Top achievements
Rank 1
hk proj asked on 27 Aug 2009, 09:49 AM
Hi, I'm having troubles with $get.
I have a <asp:HiddenField> on my page and I want to read its value using Javascript.
the HiddenField's ID is 'reloadUrl'. I  tried the following methods:
var control = $get("reloadUrl");
var control = $get("<%= reloadUrl.ClientID %>");
var control = $get("<%= this.reloadUrl.ClientID %>");
But all of them return the following message: "$get(...) is null"

My page is a content page and the HiddenField is nested in two or three controls.
What can I do?

PS: I have a RadAjaxManagerProxy on my content page and a RadAjaxManager & ScriptManager on my master page.
May be I have to use another function provided my RadAjaxManager..?

4 Answers, 1 is accepted

Sort by
0
hk proj
Top achievements
Rank 1
answered on 28 Aug 2009, 08:18 AM
I also tried to use $get with Telerik products, but nothing happened.
Can you help me? It's urgent.
0
SamJ
Top achievements
Rank 1
answered on 03 Sep 2009, 06:12 AM
HI,

$get() is the right method to access server controls. And for the Telerik controls use the $find() method.
Could you specify where is the javascript code situated, when it is called and how are the controls loaded? You can try getting reference with $get() to a control client-side object in the content page, not in the user control and see if it works.
0
hk proj
Top achievements
Rank 1
answered on 03 Sep 2009, 07:31 AM

I tried the $find method and the $get method with telerik controls and with asp controls.

I used the javascript code in FireBug (a firefox extension that provides a js shell) and in the address bar using javascript:alert($get("..."));

But nothing happens, I only get the result 'null'; I also tried to insert the javascript code in a function and call it... but the result is always null.

The only thing to note is that the $get method works with client-side controls (for example <input id="test" type="..." />) but doesn't work with $find.

What can I do?

0
SamJ
Top achievements
Rank 1
answered on 03 Sep 2009, 10:43 AM
Hi,

I am not sure if you can use the %get() method the way you did. However, if you try the below javascript, you will see how it works:

<script type="text/javascript"
function pageLoad() 
    var hidden = $get("<%= reloadUrl.ClientID %>"); 
    alert(hidden.value); 
    var telerikControl = $find("<%= RadTextBox1.ClientID %>"); 
    alert(telerikControl); 
</script> 

<telerik:RadTextBox ID="RadTextBox1" runat="server" /> 
Tags
Ajax
Asked by
hk proj
Top achievements
Rank 1
Answers by
hk proj
Top achievements
Rank 1
SamJ
Top achievements
Rank 1
Share this question
or