Get Raddock object in javascript

2 posts, 0 answers
  1. Kamalesh Patel
    Kamalesh Patel avatar
    5 posts
    Member since:
    Aug 2007

    Posted 22 Jul 2011 Link to this post

    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


     

  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 26 Jul 2011 Link to this post

    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!

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top