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

Get Raddock object in javascript

1 Answer 65 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Kamalesh Patel
Top achievements
Rank 1
Kamalesh Patel asked on 22 Jul 2011, 06:07 AM

Below code is placed in page  designer (page level).

<

 

telerik:RadScriptBlock runat="server" ID="RadScriptBlock2">

 

 

 

function

 

openFormReserve() {

 

 

    var dock = $find("<%= RadDock3.ClientID %>");

 

 

    // Center the RadDock on the screen

 

 

    var viewPort = $telerik.getViewPortSize();

 

 

    var xPos = Math.round((viewPort.width - parseInt(dock.get_width())) / 2);

 

 

    var yPos = Math.round((viewPort.height - parseInt(dock.get_height())) / 2);

 

    $telerik.setLocation(dock.get_element(), { x: xPos, y: yPos });

    dock.set_closed(

false);

 

 

    //var descriptionTextBox = $get('<%= ComboFacility.ClientID %>');

 

    Sys.Application.remove_load(openFormReserve);


}

 

 

</telerik:RadScriptBlock>


If I placed this javascript function in Javascript file (Sample.js) and assing link to this js file.

During executing script, the first line of javascript function get the null value.
var dock = $find("<%= RadDock3.ClientID %>");

Main reason is I do not want to place this javascript function at page level, and placing it js file. then How can i get the radcontrol object in javascript function.

Please do provide small sample example.

Thanks and Regards


 

1 Answer, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 26 Jul 2011, 09:35 AM
Hello Kamalesh,

Please note that the problem you are having is general knowledge, while our support system is focused on providing workarounds for bugs and incompliances, related to the RadControls. Nevertheless I can suggest a solution to your problem. Usually the ClientID cannot be accessed directly in an external JavaScript file, but there are workarounds for achieving this:
  • 1. Defining a global variable with the ClientID as a value, and accessing it in the external file.
  • 2. Adding a hidden field and setting its value with the ClientID of the control, then accessing it in the external file.
  • 3. Passing the ClientID as a parameter of the JS function.
Please check this search for more information on additional approaches, as well as on the listed above. I have also attached a sample project, demonstrating a possible solution for such scenario.

All the best,
Slav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Dock
Asked by
Kamalesh Patel
Top achievements
Rank 1
Answers by
Slav
Telerik team
Share this question
or