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

$find returns null after RadWindow is closed

7 Answers 217 Views
Window
This is a migrated thread and some comments may be shown as answers.
Dusan
Top achievements
Rank 1
Dusan asked on 09 Apr 2013, 04:18 PM
Hello,

I have a nested RadWindow in RadListView control which I managed to open, but after it is closed, I cannot open it anymore because the $find function returns null.

I don't need it to open on page load, it should be opened when user clicks on the <a> element.

It should do a postback only when user clicks on the button that will be inside the window (which I left out in the following code because that part is not implemented yet).

Current code:

<telerik:RadAjaxPanel runat="server" ID="rapConfiguration" LoadingPanelID="ralpConfiguration">
          <telerik:RadWindow ID="modalPopup" runat="server" Width="360px" Height="360px">
               <ContentTemplate>
                    <p style="text-align: center;">
                         Random text.
                    </p>
               </ContentTemplate>
          </telerik:RadWindow>
 
    <a href="javascript:void(0)" onclick="OpenDialog(); return false">
        <div style="width:180px; float:left; margin-top:10px; margin-bottom:10px;">
            <div style="width:180px; float:left; text-align:center;"><img src="../Images/add_user.png" width="60px" height="60px" /></div>
            <div style="margin-top:5px; width:180px; float:left; text-align:center; font-family: Arial, Helvetica, sans-serif;">Add users</div>
        </div>
    </a>
</telerik:RadAjaxPanel>
<telerik:RadCodeBlock runat="server" ID="rdbScripts">
<script type="text/javascript">
        function OpenDialog() {
            var temp = $('div[id$="modalPopup"]').first();
            var wnd = $find(temp.attr("id"));
             wnd.show();
         }
</script>      
</telerik:RadCodeBlock>



Thank you.

7 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 10 Apr 2013, 10:52 AM
Hello Dusan,

RadWindow renders its markup when it is shown for the first time, and it uses JavaScript to do this. This markup is also rendered as a first child of the form element and has the following id "RadWindowWrapper_" concatenated with the ClientID of the cotnrol. Therefore, the second time your function passes "RadWindowWrapper_modalPopup" as an argument to $find() and this will return null, because it only needs "modalPopup",

I can suggest two ways to work around it:
1) use no server code blocks and account for that prefix. This is the more complex way:
var temp = $('div[id$="modalPopup"]').first();
var ctrlId = temp.attr("id");
var strPrefix = "";
if (ctrlId.indexOf("RadWindowWrapper_") > -1)
{
    strPrefix = "RadWindowWrapper_";
}
var wnd = $find(ctrlId.substring(strPrefix.length));
wnd.show();

OR

2) use a server code block to get the ID:
var wnd = $find("<%=modalPopup.ClientID %>");
wnd.show();


All the best,
Marin Bratanov
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
Dusan
Top achievements
Rank 1
answered on 10 Apr 2013, 02:45 PM
Hello Marin,

First code works like a charm. I cannot use second since it is nested and <% %> gives me exception.

Keep up with good work.

0
Marin Bratanov
Telerik team
answered on 12 Apr 2013, 02:45 PM
Hello,

The following article explains why this error occurs and how to fix it: http://www.telerik.com/help/aspnet-ajax/ajax-radscriptblock-radcodeblock.html.


Greetings,
Marin Bratanov
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
Dan
Top achievements
Rank 1
answered on 12 Aug 2013, 08:35 PM
Hi,

Marin, I'm using your option #2 but I still get a null reference to my mapWindow object:

var mapWindow = $find("<%=MapWindow.ClientID%>");

mapWindow.show();

Thanks for any help you could provide.

Dan

0
A2H
Top achievements
Rank 1
answered on 12 Aug 2013, 10:54 PM
Hello Dan,

Please try this

var $ = $telerik.$;
var mapWindow = $find("<%=MapWindow.ClientID%>");
mapWindow.show();


Thanks,
A2H
0
Marin Bratanov
Telerik team
answered on 13 Aug 2013, 09:18 AM
Hi guys,

If this throws an error only after the RadWindow has been opened and closed once then the most likely reason for the problem is that its DestroyOnClose property is set to true, so its client-side object that $find() should return is disposed. Setting it to false should resolve this issue.

In case you are attemting to call this function from the server code it is possible that it is executed too early and for that I would advise that you examine this sticky thread: http://www.telerik.com/community/forums/aspnet-ajax/window/opening-radwindow-from-the-server.aspx.


Regards,
Marin Bratanov
Telerik
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 the blog feed now.
0
Dan
Top achievements
Rank 1
answered on 13 Aug 2013, 01:12 PM
That was my problem, I was setting the DestroyOnClose to true. 

Thanks!
Dan
Tags
Window
Asked by
Dusan
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Dusan
Top achievements
Rank 1
Dan
Top achievements
Rank 1
A2H
Top achievements
Rank 1
Share this question
or