
khaled jendi
Top achievements
Rank 1
khaled jendi
asked on 16 Aug 2012, 07:57 PM
hi,
I am using this code to change time value in javascript:
var timePicker = $find('<%= From_Time.ClientID %>');
timePicker.get_dateInput().set_value("01:00 PM");
but I got error says timePicker is null !
I have checked control ID, its correct, I don't know what is the problem
help please !
I am using this code to change time value in javascript:
var timePicker = $find('<%= From_Time.ClientID %>');
timePicker.get_dateInput().set_value("01:00 PM");
but I got error says timePicker is null !
I have checked control ID, its correct, I don't know what is the problem
help please !
9 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 17 Aug 2012, 06:57 AM
Hi khaled jendi,
Using $find("<%= SomeControl.ClientID %>") is the recommended way to get reference to client-side objects. What it does it to output the generated client-id in the final markup of your page.
The $find() routine may fail in the occasion when the control is not yet initialized. All ASP.NET Ajax controls are initialized when the page is fully loaded - the required initialization statements are output at the end of the page just before closing the form tag.
The workaround here is to register your code after control initialization. This can be done in the following ways:
1) Define a pageLoad method JavaScript method which is called on initial load and after ajax updates.
2) Subscribe to the load event of the Sys.Application javascript object. The pageLoad method mentioned earlier is just a shortcut to this event
3) Use window.setTimeout. This would just delay the execution of your code and may need tweaking to find the timeout which works.
Hope this helps.
Regards,
Princy.
Using $find("<%= SomeControl.ClientID %>") is the recommended way to get reference to client-side objects. What it does it to output the generated client-id in the final markup of your page.
The $find() routine may fail in the occasion when the control is not yet initialized. All ASP.NET Ajax controls are initialized when the page is fully loaded - the required initialization statements are output at the end of the page just before closing the form tag.
The workaround here is to register your code after control initialization. This can be done in the following ways:
1) Define a pageLoad method JavaScript method which is called on initial load and after ajax updates.
2) Subscribe to the load event of the Sys.Application javascript object. The pageLoad method mentioned earlier is just a shortcut to this event
3) Use window.setTimeout. This would just delay the execution of your code and may need tweaking to find the timeout which works.
Hope this helps.
Regards,
Princy.
0

khaled jendi
Top achievements
Rank 1
answered on 17 Aug 2012, 11:11 AM
but isn't .ready() function is page load?
(function ($) {
$(document).ready(function () {
var timePicker = $find('<%= From_Time.ClientID %>');
timePicker.get_dateInput().set_value("01:00 PM");
});
})(jQuery);
(function ($) {
$(document).ready(function () {
var timePicker = $find('<%= From_Time.ClientID %>');
timePicker.get_dateInput().set_value("01:00 PM");
});
})(jQuery);
0

khaled jendi
Top achievements
Rank 1
answered on 17 Aug 2012, 11:15 AM
by the way, I have tried page load but didnt work with me:
function pageLoad(sender, args) {
var timePicker = $find('<%= From_Time.ClientID %>');
timePicker.get_dateInput().set_value("01:00 PM");
}
even this didnt work with me !
(function ($) {
$(document).ready(function () {
Sys.Application.add_load(function () {
alert("reaching_this_point");
var timePicker = $find('<%= From_Time.ClientID %>');
timePicker.get_dateInput().set_value("01:00 PM");
});
});
})(jQuery);
function pageLoad(sender, args) {
var timePicker = $find('<%= From_Time.ClientID %>');
timePicker.get_dateInput().set_value("01:00 PM");
}
even this didnt work with me !
(function ($) {
$(document).ready(function () {
Sys.Application.add_load(function () {
alert("reaching_this_point");
var timePicker = $find('<%= From_Time.ClientID %>');
timePicker.get_dateInput().set_value("01:00 PM");
});
});
})(jQuery);
0

Princy
Top achievements
Rank 2
answered on 20 Aug 2012, 06:43 AM
Hi,
You can access the TimePicker with jquery as shown below.
JS:
Thanks,
Princy.
You can access the TimePicker with jquery as shown below.
JS:
<script type=
"text/javascript"
>
$(document).ready(
function
() {
alert(
"reaching_this_point"
);
var
timePicker = $(
'From_Time'
);
//using jquery
timePicker.get_dateInput().set_value(
"01:00 PM"
);
});
function
pageLoad()
{
var
timePicker = $find(
'<%= From_Time.ClientID %>'
);
timePicker.get_dateInput().set_value(
"01:00 PM"
);
}
</script>
Thanks,
Princy.
0

khaled jendi
Top achievements
Rank 1
answered on 20 Aug 2012, 09:35 AM
hi,
I copy paste same source code, but still I ma getting the error !
this is aspx source:
<telerik:RadTimePicker ID="From_Time" runat="server" MinDate="1900-01-01" EnableShadows="true"
AutoPostBack="True" Culture="en-GB"
DateInput-Enabled="false" Width="200px" Skin="WebBlue" >
<TimeView ID="TimeView1" CellSpacing="-1" Culture="en-GB" runat="server" Columns="7" TimeFormat="hh:mm tt"></TimeView>
</telerik:RadTimePicker>
I copy paste same source code, but still I ma getting the error !
this is aspx source:
<telerik:RadTimePicker ID="From_Time" runat="server" MinDate="1900-01-01" EnableShadows="true"
AutoPostBack="True" Culture="en-GB"
DateInput-Enabled="false" Width="200px" Skin="WebBlue" >
<TimeView ID="TimeView1" CellSpacing="-1" Culture="en-GB" runat="server" Columns="7" TimeFormat="hh:mm tt"></TimeView>
</telerik:RadTimePicker>
0

khaled jendi
Top achievements
Rank 1
answered on 20 Aug 2012, 09:51 AM
I was checking all controls I have in my page, any one is null !
moreover, I have tried to find the control in a click button event, so when I click button, the $find function select the control, but even though, I got any rad control null !!!!!
moreover, I have tried to find the control in a click button event, so when I click button, the $find function select the control, but even though, I got any rad control null !!!!!
0
Hi Khaled,
Thank you for contacting us.
I have created a sample web site to demonstrate that accessing the RadDateTimePicker on client-side works as expected. Please check out the attached application and try to distinguish the crucial differences between our projects.
In addition, please note that when DateInput of the picker is disabled, its value will not be preserved on the server.
Furthermore, the suggested approach $find is for use only in internal script declarations and not .js external files.
I hope this will prove helpful.
All the best,
Eyup
the Telerik team
Thank you for contacting us.
I have created a sample web site to demonstrate that accessing the RadDateTimePicker on client-side works as expected. Please check out the attached application and try to distinguish the crucial differences between our projects.
In addition, please note that when DateInput of the picker is disabled, its value will not be preserved on the server.
Furthermore, the suggested approach $find is for use only in internal script declarations and not .js external files.
I hope this will prove helpful.
All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

khaled jendi
Top achievements
Rank 1
answered on 22 Aug 2012, 05:49 PM
hi,
please find the attached link of my test project, as I am still getting null value,
I need when I click the button of the project, I need to set value of rad time picker,
here is link, please help!
http://www.mediafire.com/?pv6qpb9tr94subg
please find the attached link of my test project, as I am still getting null value,
I need when I click the button of the project, I need to set value of rad time picker,
here is link, please help!
http://www.mediafire.com/?pv6qpb9tr94subg
0
Hello Khaled,
I have downloaded your file and noticed that you are using
var picker = $find("<%=ddlMachines.ClientID%>"); in an external .js file. Please note that you cannot use server-side expressions in external javascript files such as:
ASP.NET framework does not process external javascript files and does not parse the code blocks ( <%= ... %> syntax). Such blocks are parsed only in aspx/ascx files so what we can suggest is moving the javascript in the original aspx file or getting the client-side object of the combobox assigning it to a global javascript variable in the aspx using the <%= ... %> syntax and then passing it as a parameter to the external .js functions to get hold of the client-component of the control.
Please check out the following thread for further clarification:
http://www.telerik.com/community/forums/aspnet-ajax/ajax/radscriptblock-with-external-js-file.aspx
I hope this will help.
Regards,
Eyup
the Telerik team
I have downloaded your file and noticed that you are using
var picker = $find("<%=ddlMachines.ClientID%>"); in an external .js file. Please note that you cannot use server-side expressions in external javascript files such as:
Copy Code
$find("<%= RadComboBox1.ClientID %>");
ASP.NET framework does not process external javascript files and does not parse the code blocks ( <%= ... %> syntax). Such blocks are parsed only in aspx/ascx files so what we can suggest is moving the javascript in the original aspx file or getting the client-side object of the combobox assigning it to a global javascript variable in the aspx using the <%= ... %> syntax and then passing it as a parameter to the external .js functions to get hold of the client-component of the control.
Please check out the following thread for further clarification:
http://www.telerik.com/community/forums/aspnet-ajax/ajax/radscriptblock-with-external-js-file.aspx
I hope this will help.
Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.