$find returns null after RadWindow is closed

8 posts, 1 answers
  1. Dusan
    Dusan avatar
    2 posts
    Member since:
    Apr 2013

    Posted 09 Apr 2013 Link to this post

    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.
  2. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 10 Apr 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dusan
    Dusan avatar
    2 posts
    Member since:
    Apr 2013

    Posted 10 Apr 2013 Link to this post

    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.

  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 12 Apr 2013 Link to this post

    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.
  6. Dan
    Dan avatar
    3 posts
    Member since:
    Aug 2010

    Posted 12 Aug 2013 Link to this post

    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

  7. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 12 Aug 2013 Link to this post

    Hello Dan,

    Please try this

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


    Thanks,
    A2H
  8. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 13 Aug 2013 Link to this post

    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.
  9. Dan
    Dan avatar
    3 posts
    Member since:
    Aug 2010

    Posted 13 Aug 2013 Link to this post

    That was my problem, I was setting the DestroyOnClose to true. 

    Thanks!
    Dan
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017