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

$find return null after PostBack

5 Answers 564 Views
Window
This is a migrated thread and some comments may be shown as answers.
Corentin
Top achievements
Rank 1
Corentin asked on 05 Mar 2019, 10:20 AM

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

5 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 05 Mar 2019, 12:53 PM
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.
0
Corentin
Top achievements
Rank 1
answered on 05 Mar 2019, 01:43 PM

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

0
Rumen
Telerik team
answered on 05 Mar 2019, 02:26 PM
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.
0
Corentin
Top achievements
Rank 1
answered on 05 Mar 2019, 03:42 PM

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

0
Rumen
Telerik team
answered on 05 Mar 2019, 04:16 PM
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.
Tags
Window
Asked by
Corentin
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Corentin
Top achievements
Rank 1
Share this question
or