$find return null after PostBack

6 posts, 0 answers
  1. Corentin
    Corentin avatar
    4 posts
    Member since:
    Oct 2015

    Posted 05 Mar Link to this post

    Hi,

     

    I have a page where I user a RadWindowManager and buttons calling postback functions.
    To open my RadWindow, I use this traditional code : 

        var oWnd = $find("<%= RadWindow.ClientID %>");
        oWnd.show();

    It work fine until one button is fired and postback is done.
    After that postback, $find return null every time.

    Does someone have a tips to resolve that issue ?

    Thanks,
    Corentin

  2. Rumen
    Admin
    Rumen avatar
    14010 posts

    Posted 05 Mar Link to this post

    Hi Corentin,

    Usually your code should work properly even after postback.

    Is it possible that the ID of the window gets changed after postback or the window object not created due to an error?

    Here is how to inspect what ID is generated before and after postback:
    Right click over the window title icon, choose Inspect from the browser content menu and go to the parent div wrapper of the window to see the ID, which should be something similar to:

    RadWindowWrapper_ctl00_ContentPlaceholder1_RadWindow1

    at least this is the div wrapper ID in the Overview demo: https://demos.telerik.com/aspnet-ajax/window/examples/overview/defaultcs.aspx.

    Delete the beginning RadWindowWrapper_ string to get the real ID of the window, which will allow you to get reference to it via the $find("ctl00_ContentPlaceholder1_RadWindow1") method.

    Do the same inspection after the postback to see whether the ID has been changed and a different one assigned to the window.

    For your convenience I created a video demonstration.


    Best regards,
    Rumen
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Corentin
    Corentin avatar
    4 posts
    Member since:
    Oct 2015

    Posted 05 Mar in reply to Rumen Link to this post

    Hi Rumen,

    After investigation, it seems that the element still exists with the same ID (using jquery with the ID is always available)

    After page loading : 
    $find("ctl00_ContentPlaceHolder1_PageRadWindow") => return an object, OK
    $("#ctl00_ContentPlaceHolder1_PageRadWindow") => return a jquery object OK

    After postback : 
    $find("ctl00_ContentPlaceHolder1_PageRadWindow") => return null, KO
    $("#ctl00_ContentPlaceHolder1_PageRadWindow") => return a jquery object OK

    I don't understand why ... 

    Best regards,
    Corentin

  4. Rumen
    Admin
    Rumen avatar
    14010 posts

    Posted 05 Mar Link to this post

    Hi,

    In such case you can use this syntax to get reference to the client-object of RadWindow:

    var window1 = $telerik.$("#ctl00_ContentPlaceholder1_RadWindow1").get(0).control;
    window1.set_height(100);

    Regards,
    Rumen
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Corentin
    Corentin avatar
    4 posts
    Member since:
    Oct 2015

    Posted 05 Mar in reply to Rumen Link to this post

    Hi,

    Thanks for your answer.
    I've tried your code, and it is fonctional before the postback, but after the postback call, the ".control" became undefined (the previous parts work fine)

    Thanks,
    Corentin

  6. Rumen
    Admin
    Rumen avatar
    14010 posts

    Posted 05 Mar Link to this post

    Hi,

    Please take a look at the following forum discussion on the topic: https://www.telerik.com/forums/client-id-changes-on-postback.

    Regards,
    Rumen
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top